Skip to content

Commit

Permalink
refactor: fix argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
anilmisirlioglu committed Oct 4, 2021
1 parent e949952 commit 0f04aed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.16

require (
github.com/fatih/color v1.12.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/manifoldco/promptui v0.8.0
github.com/mitchellh/go-homedir v1.1.0
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWs
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU=
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand Down
13 changes: 6 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/hex"
"fmt"
"github.com/fatih/color"
"github.com/google/shlex"
"github.com/manifoldco/promptui"
"github.com/mitchellh/go-homedir"
"io"
Expand Down Expand Up @@ -171,19 +172,17 @@ func main() {
editor = "vim"

if runtime.GOOS == "windows" {
editor = "notepad++"
editor = "notepad"
}
}

split := strings.Split(editor, " ")
split = append(split, gitConfig)

executableEditor, err := exec.LookPath(split[0])
split, err := shlex.Split(editor)
if err != nil {
color.HiRed("Please set the $EDITOR environment variable or install vim.")
split = []string{strings.Split(editor, " ")[0]}
}
split = append(split, gitConfig)

cmd := exec.Command(executableEditor, split[1:]...)
cmd := exec.Command(split[0], split[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 0f04aed

Please sign in to comment.