From 807022f6180ec3a0ae87b6a6f396e5f00a9d62c3 Mon Sep 17 00:00:00 2001 From: rsteube Date: Sat, 18 Feb 2023 12:43:29 +0100 Subject: [PATCH] run: support slice flags --- run.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/run.go b/run.go index e0a28a0..6ddb792 100644 --- a/run.go +++ b/run.go @@ -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 {