diff options
author | mjarkk <mkopenga@gmail.com> | 2018-11-10 08:57:02 +0100 |
---|---|---|
committer | mjarkk <mkopenga@gmail.com> | 2018-11-10 08:57:02 +0100 |
commit | 834e42897d5c2190a7f108d9be5c910138c1199e (patch) | |
tree | 7b97e01bb243da689445d9e9ce19ac872066d62d /pkg | |
parent | 500267417b9779822e908ba7997f9adb9c881cac (diff) |
Switched back to github.com/mgutz/str instaid of a copy of ToArgv
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/exec_live_default.go | 3 | ||||
-rw-r--r-- | pkg/commands/os.go | 3 | ||||
-rw-r--r-- | pkg/commands/string-to-args.go | 114 |
3 files changed, 4 insertions, 116 deletions
diff --git a/pkg/commands/exec_live_default.go b/pkg/commands/exec_live_default.go index 9e39585bc..685974a1b 100644 --- a/pkg/commands/exec_live_default.go +++ b/pkg/commands/exec_live_default.go @@ -11,6 +11,7 @@ import ( "unicode/utf8" "github.com/kr/pty" + "github.com/mgutz/str" ) // RunCommandWithOutputLiveWrapper runs a command and return every word that gets written in stdout @@ -21,7 +22,7 @@ import ( func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) { cmdOutput := []string{} - splitCmd := ToArgv(command) + splitCmd := str.ToArgv(command) cmd := exec.Command(splitCmd[0], splitCmd[1:]...) cmd.Env = os.Environ() diff --git a/pkg/commands/os.go b/pkg/commands/os.go index 65e25271b..7f2ddde25 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -9,6 +9,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/mgutz/str" "github.com/sirupsen/logrus" gitconfig "github.com/tcnksm/go-gitconfig" ) @@ -49,7 +50,7 @@ func NewOSCommand(log *logrus.Entry, config config.AppConfigurer) *OSCommand { // RunCommandWithOutput wrapper around commands returning their output and error func (c *OSCommand) RunCommandWithOutput(command string) (string, error) { c.Log.WithField("command", command).Info("RunCommand") - splitCmd := ToArgv(command) + splitCmd := str.ToArgv(command) c.Log.Info(splitCmd) return sanitisedCommandOutput( c.command(splitCmd[0], splitCmd[1:]...).CombinedOutput(), diff --git a/pkg/commands/string-to-args.go b/pkg/commands/string-to-args.go deleted file mode 100644 index 88999e9bd..000000000 --- a/pkg/commands/string-to-args.go +++ /dev/null @@ -1,114 +0,0 @@ -// ToArgv is copied from github.com/mgutz/str - -package commands - -import "runtime" - -// ToArgv converts string s into an argv for exec. -func ToArgv(s string) []string { - const ( - InArg = iota - InArgQuote - OutOfArg - ) - currentState := OutOfArg - currentQuoteChar := "\x00" // to distinguish between ' and " quotations - // this allows to use "foo'bar" - currentArg := "" - argv := []string{} - - isQuote := func(c string) bool { - return c == `"` || c == `'` - } - - isEscape := func(c string) bool { - return c == `\` - } - - isWhitespace := func(c string) bool { - return c == " " || c == "\t" - } - - L := len(s) - for i := 0; i < L; i++ { - c := s[i : i+1] - - //fmt.Printf("c %s state %v arg %s argv %v i %d\n", c, currentState, currentArg, args, i) - if isQuote(c) { - switch currentState { - case OutOfArg: - currentArg = "" - fallthrough - case InArg: - currentState = InArgQuote - currentQuoteChar = c - - case InArgQuote: - if c == currentQuoteChar { - currentState = InArg - } else { - currentArg += c - } - } - - } else if isWhitespace(c) { - switch currentState { - case InArg: - argv = append(argv, currentArg) - currentState = OutOfArg - case InArgQuote: - currentArg += c - case OutOfArg: - // nothing - } - - } else if isEscape(c) { - switch currentState { - case OutOfArg: - currentArg = "" - currentState = InArg - fallthrough - case InArg: - fallthrough - case InArgQuote: - if i == L-1 { - if runtime.GOOS == "windows" { - // just add \ to end for windows - currentArg += c - } else { - panic("Escape character at end string") - } - } else { - if runtime.GOOS == "windows" { - peek := s[i+1 : i+2] - if peek != `"` { - currentArg += c - } - } else { - i++ - c = s[i : i+1] - currentArg += c - } - } - } - } else { - switch currentState { - case InArg, InArgQuote: - currentArg += c - - case OutOfArg: - currentArg = "" - currentArg += c - currentState = InArg - } - } - } - - if currentState == InArg { - argv = append(argv, currentArg) - } else if currentState == InArgQuote { - panic("Starting quote has no ending quote.") - } - - return argv -} |