diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-09 21:32:16 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-09 21:38:24 +0200 |
| commit | a92faf7689fa01595fd613ddd3880e9c301ed558 (patch) | |
| tree | f6607fa23ac41385f9f18d8ed6ad0f970c4ba6df /pkg/rtree/remote.go | |
| parent | a4dfbab3b06360245f6b2fce4b56d6caf2729f8f (diff) | |
| download | gofu-a92faf7689fa01595fd613ddd3880e9c301ed558.tar.gz | |
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.
Diffstat (limited to 'pkg/rtree/remote.go')
| -rw-r--r-- | pkg/rtree/remote.go | 14 |
1 files changed, 6 insertions, 8 deletions
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 |
