From 85460de680f51f8595423a529608c668296e9c16 Mon Sep 17 00:00:00 2001 From: rsteube Date: Sat, 13 Jan 2024 14:26:19 +0100 Subject: [PATCH] util: moved FormatArgs to carapace-shlex --- go.mod | 2 +- go.sum | 4 ++-- pkg/execlog/execlog.go | 6 +++--- pkg/util/format.go | 27 --------------------------- 4 files changed, 6 insertions(+), 33 deletions(-) delete mode 100644 pkg/util/format.go diff --git a/go.mod b/go.mod index ad4f9966..aad35199 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 f23fabb2..d7993ce6 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 a4f1f1ae..6b093f28 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 1bf2d922..00000000 --- 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, " ") -}