Skip to content

Commit

Permalink
fix execute macro and env
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed May 5, 2022
1 parent 042b8c5 commit aca4d46
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ commands:
- ["pos1A", "pos1B"]
- ["$files"]
- ["$directories"]
- ["$(echo \"pos: $CARAPACE_ARG0 flag: $CARAPACE_FLAG_STYLED\")"]
- ["$(echo \"pos: $C_ARG0 flag: $C_FLAG_STYLED\")"]
positionalany: ["posAny1", "posAny2"]
dash:
- ["dash1", "dash2"]
Expand Down
8 changes: 6 additions & 2 deletions macro.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ func MacroI[T any](f func(t T) carapace.Action) Macro {
return Macro{
Func: func(s string) carapace.Action {
var t T
if err := yaml.Unmarshal([]byte(s), &t); err != nil {
return carapace.ActionMessage(err.Error())
if reflect.TypeOf(t).Kind() == reflect.String {
reflect.ValueOf(&t).Elem().SetString(s)
} else {
if err := yaml.Unmarshal([]byte(s), &t); err != nil {
return carapace.ActionMessage(err.Error())
}
}
return f(t)
},
Expand Down
2 changes: 1 addition & 1 deletion spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func parseAction(cmd *cobra.Command, arr []string) carapace.Action {
} else if nospace {
return batch.ToA().NoSpace()
}
return batch.ToA()
return batch.ToA().Invoke(c).ToA()
})
}

Expand Down

0 comments on commit aca4d46

Please sign in to comment.