Skip to content

Commit

Permalink
Merge pull request #138 from rsteube/run-slice
Browse files Browse the repository at this point in the history
run: support slice flags
  • Loading branch information
rsteube authored Feb 18, 2023
2 parents c1bb62f + 807022f commit 5c60950
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func (r run) parse() func(cmd *cobra.Command, args []string) error {

context := carapace.NewContext(args...)
cmd.Flags().Visit(func(f *pflag.Flag) {
context.Setenv(fmt.Sprintf("C_FLAG_%v", strings.ToUpper(f.Name)), f.Value.String())
if slice, ok := f.Value.(pflag.SliceValue); ok {
context.Setenv(fmt.Sprintf("C_FLAG_%v", strings.ToUpper(f.Name)), strings.Join(slice.GetSlice(), ","))
} else {
context.Setenv(fmt.Sprintf("C_FLAG_%v", strings.ToUpper(f.Name)), f.Value.String())
}
})
var err error
for index, mArg := range mArgs {
Expand Down

0 comments on commit 5c60950

Please sign in to comment.