feat: support complex toolArgs

This commit is contained in:
yory8 2020-02-25 10:08:02 +01:00
parent 2b30ada83d
commit f58fb5133e
3 changed files with 13 additions and 2 deletions

1
go.mod
View file

@ -5,5 +5,6 @@ go 1.13
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

2
go.sum
View file

@ -4,6 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View file

@ -7,9 +7,11 @@ import (
"os/exec"
"strconv"
"strings"
"github.com/kballard/go-shellquote"
)
func selector(data []string, max int, tool string, prompt string, toolsArgs string) (string, error) {
func selector(data []string, max int, tool string, prompt string, toolArgs string) (string, error) {
if len(data) == 0 {
return "", errors.New("nothing to show: no data available")
}
@ -46,7 +48,13 @@ func selector(data []string, max int, tool string, prompt string, toolsArgs stri
return "", fmt.Errorf("unsupported tool: %s", tool)
}
args = append(args, strings.Fields(toolsArgs)...)
if len(toolArgs) > 0 {
targs, err := shellquote.Split(toolArgs)
if err != nil {
return "", fmt.Errorf("selector: %w", err)
}
args = append(args, targs...)
}
processed, guide := preprocessData(data, true, false)