Skip to content

Commit

Permalink
exposed ActionMacro
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed May 8, 2022
1 parent d8b70b5 commit 11a1165
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion macro.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func AddMacro(s string, m Macro) {
macros["_"+s] = m
}

func parseMacro(s string) carapace.Action {
// ActionMacro completes given macro
func ActionMacro(s string) carapace.Action {
r := regexp.MustCompile(`^\$(?P<macro>[^(]*)(\((?P<arg>.*)\))?$`)
if !r.MatchString(s) {
return carapace.ActionMessage(fmt.Sprintf("malformed macro: '%v'", s))
Expand Down
2 changes: 1 addition & 1 deletion spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func parseAction(cmd *cobra.Command, arr []string) carapace.Action {
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))
batch = append(batch, ActionMacro(elemSubst))
} else {
vals = append(vals, parseValue(elemSubst)...)
}
Expand Down

0 comments on commit 11a1165

Please sign in to comment.