diff --git a/go.mod b/go.mod index ad4f99664..aad351997 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/rsteube/carapace go 1.15 require ( - github.com/rsteube/carapace-shlex v0.1.1 + github.com/rsteube/carapace-shlex v0.1.2 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index f23fabb2d..d7993ce61 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/rsteube/carapace-shlex v0.1.1 h1:fRQEBBKyYKm4TXUabm4tzH904iFWSmXJl3UZhMfQNYU= -github.com/rsteube/carapace-shlex v0.1.1/go.mod h1:zPw1dOFwvLPKStUy9g2BYKanI6bsQMATzDMYQQybo3o= +github.com/rsteube/carapace-shlex v0.1.2 h1:ZKjhIfXoCkEnzensMglTaLbkNOaLkmM8SCRshpJKx6s= +github.com/rsteube/carapace-shlex v0.1.2/go.mod h1:zPw1dOFwvLPKStUy9g2BYKanI6bsQMATzDMYQQybo3o= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= diff --git a/pkg/execlog/execlog.go b/pkg/execlog/execlog.go index a4f1f1ae8..6b093f28f 100644 --- a/pkg/execlog/execlog.go +++ b/pkg/execlog/execlog.go @@ -1,8 +1,8 @@ package execlog import ( + shlex "github.com/rsteube/carapace-shlex" "github.com/rsteube/carapace/internal/log" - "github.com/rsteube/carapace/pkg/util" "github.com/rsteube/carapace/third_party/golang.org/x/sys/execabs" ) @@ -19,12 +19,12 @@ func Command(name string, arg ...string) *Cmd { } func (c *Cmd) Run() error { - log.LOG.Printf("executing %#v", util.FormatCmd(c.Args...)) + log.LOG.Printf("executing %#v", shlex.Join(c.Args)) return c.Cmd.Run() } func (c *Cmd) Start() error { - log.LOG.Printf("executing %#v", util.FormatCmd(c.Args...)) + log.LOG.Printf("executing %#v", shlex.Join(c.Args)) return c.Cmd.Start() } diff --git a/pkg/util/format.go b/pkg/util/format.go deleted file mode 100644 index 1bf2d9224..000000000 --- a/pkg/util/format.go +++ /dev/null @@ -1,27 +0,0 @@ -package util - -import ( - "fmt" - "strings" -) - -// FormatCmd joins given args to a formatted command. -// TODO experimental -func FormatCmd(args ...string) string { - replacer := strings.NewReplacer( - "$", "\\$", - "`", "\\`", - ) - - formatted := make([]string, 0, len(args)) - for _, arg := range args { - switch { - case arg == "", - strings.ContainsAny(arg, `"' `+"\n\r\t"): - formatted = append(formatted, replacer.Replace(fmt.Sprintf("%#v", arg))) - default: - formatted = append(formatted, arg) - } - } - return strings.Join(formatted, " ") -}