diff --git a/example/example.yaml b/example/example.yaml index 0234cc1..89805a7 100644 --- a/example/example.yaml +++ b/example/example.yaml @@ -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"] diff --git a/macro.go b/macro.go index 8ba0199..f307c25 100644 --- a/macro.go +++ b/macro.go @@ -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) }, diff --git a/spec.go b/spec.go index d557617..ab2e6c5 100644 --- a/spec.go +++ b/spec.go @@ -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() }) }