File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -230,6 +230,52 @@ That flag can then be set with `--lang spanish` or `-l spanish`. Note that
230
230
giving two different forms of the same flag in the same command invocation is an
231
231
error.
232
232
233
+ #### Multiple Values per Single Flag
234
+
235
+ Using a slice flag allows you to pass multiple values for a single flag; the values will be provided as a slice:
236
+
237
+ - ` Int64SliceFlag `
238
+ - ` IntSliceFlag `
239
+ - ` StringSliceFlag `
240
+
241
+ <!-- {
242
+ "args": ["--greeting Hello", "--greeting Hola"],
243
+ "output": "Hello, Hola"
244
+ } -->
245
+ ``` go
246
+ package main
247
+
248
+ import (
249
+ " fmt"
250
+ " log"
251
+ " os"
252
+ " strings"
253
+
254
+ " github.com/urfave/cli/v3"
255
+ )
256
+
257
+ func main () {
258
+ app := &cli.App {
259
+ Flags: []cli.Flag {
260
+ &cli.StringSliceFlag {
261
+ Name: " greeting" ,
262
+ Usage: " Pass multiple greetings" ,
263
+ },
264
+ },
265
+ Action: func (cCtx *cli.Context ) error {
266
+ fmt.Println (strings.Join (cCtx.StringSlice (" greeting" ), ` , ` ))
267
+ return nil
268
+ },
269
+ }
270
+
271
+ if err := app.Run (os.Args ); err != nil {
272
+ log.Fatal (err)
273
+ }
274
+ }
275
+ ```
276
+
277
+ Multiple values need to be passed as separate, repeating flags, e.g. ` --greeting Hello --greeting Hola ` .
278
+
233
279
#### Ordering
234
280
235
281
Flags for the application and commands are shown in the order they are defined.
You can’t perform that action at this time.
0 commit comments