From a92faf7689fa01595fd613ddd3880e9c301ed558 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 9 May 2017 21:32:16 +0200 Subject: refactor cli.Interface yet again - Only one global instance now, so we don't need to pass it around all the time. - Allow to swap out the Command.Run implementation for unit tests. - Can now use cli.Interface during func init() of packages importing pkg/cli. --- pkg/rtree/remote.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'pkg/rtree/remote.go') diff --git a/pkg/rtree/remote.go b/pkg/rtree/remote.go index 353916d..8f88deb 100644 --- a/pkg/rtree/remote.go +++ b/pkg/rtree/remote.go @@ -19,13 +19,12 @@ package rtree import ( - "bytes" "net/url" - "os/exec" "path/filepath" "regexp" "strings" + "github.com/majewsky/gofu/pkg/cli" "github.com/majewsky/gofu/pkg/earlyerrors" ) @@ -39,16 +38,15 @@ type remoteAlias struct { var remoteAliases []*remoteAlias func init() { - cmd := exec.Command("git", "config", "--global", "-l") - var buf bytes.Buffer - cmd.Stdout = &buf - err := cmd.Run() + out, err := cli.Interface.CaptureStdout(cli.Command{ + Program: []string{"git", "config", "--global", "-l"}, + }) if err != nil { - earlyerrors.Put("exec `git config --global -l` failed: " + err.Error()) + earlyerrors.Put(err.Error()) } rx := regexp.MustCompile(`^url\.([^=]+)\.insteadof=(.+)$`) - for _, line := range strings.Split(string(buf.Bytes()), "\n") { + for _, line := range strings.Split(out, "\n") { match := rx.FindStringSubmatch(line) if match == nil { continue -- cgit v1.3.1