diff --git a/go.mod b/go.mod index 288f296..e988a68 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 replace github.com/spf13/pflag => github.com/cornfeedhobo/pflag v1.1.0 require ( - github.com/rsteube/carapace v0.20.1 + github.com/rsteube/carapace v0.20.2 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b diff --git a/go.sum b/go.sum index b75b56e..c19eeb5 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ github.com/cornfeedhobo/pflag v1.1.0/go.mod h1:ROo/cqBpAh84jplPcXiI5HTjyLmtp04Wa github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/rsteube/carapace v0.20.1 h1:ZnPtEZQGi4vSoco7yLexTvmx9X82jUaOcDScpl3v14M= -github.com/rsteube/carapace v0.20.1/go.mod h1:GgiwpPVhucHNOv0AmtIkxhiEFkCMP5BBRauyQLP0mFY= +github.com/rsteube/carapace v0.20.2 h1:i6QSQZ5vZKmXcwupsYch8XdJ/GBbZU+H8XtfXEs8Z4E= +github.com/rsteube/carapace v0.20.2/go.mod h1:GgiwpPVhucHNOv0AmtIkxhiEFkCMP5BBRauyQLP0mFY= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= diff --git a/spec.go b/spec.go index ab2e6c5..88c2d12 100644 --- a/spec.go +++ b/spec.go @@ -113,28 +113,15 @@ func parseAction(cmd *cobra.Command, arr []string) carapace.Action { }) })) - rEnv := regexp.MustCompile(`\${(?P[^}]+)}`) - batch := carapace.Batch() vals := make([]string, 0) for _, elem := range arr { - // TODO yuck - if matches := rEnv.FindAllStringSubmatch(elem, -1); matches != nil { - for _, submatches := range matches { - name := submatches[1] - for _, env := range c.Env { // TODO add Context.Getenv - splitted := strings.SplitN(env, "=", 2) - if splitted[0] == name { // TODO must be the last matching (solved with Getenv) - elem = strings.Replace(elem, submatches[0], splitted[1], 1) - } - } - } - } - - if strings.HasPrefix(elem, "$") { // macro - batch = append(batch, parseMacro(elem)) + if elemSubst, err := c.Envsubst(elem); err != nil { + batch = append(batch, carapace.ActionMessage(fmt.Sprintf("%v: %v", err.Error(), elem))) + } else if strings.HasPrefix(elemSubst, "$") { // macro + batch = append(batch, parseMacro(elemSubst)) } else { - vals = append(vals, parseValue(elem)...) + vals = append(vals, parseValue(elemSubst)...) } } batch = append(batch, carapace.ActionStyledValuesDescribed(vals...))