File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -230,6 +230,48 @@ That flag can then be set with `--lang spanish` or `-l spanish`. Note that
230230giving two different forms of the same flag in the same command invocation is an
231231error.
232232
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+ import (
248+ " fmt"
249+ " log"
250+ " os"
251+ " strings"
252+ " github.com/urfave/cli/v2"
253+ )
254+ func main () {
255+ app := &cli.App {
256+ Flags: []cli.Flag {
257+ &cli.StringSliceFlag {
258+ Name: " greeting" ,
259+ Usage: " Pass multiple greetings" ,
260+ },
261+ },
262+ Action: func (cCtx *cli.Context ) error {
263+ fmt.Println (strings.Join (cCtx.StringSlice (" greeting" ), ` , ` ))
264+ return nil
265+ },
266+ }
267+ if err := app.Run (os.Args ); err != nil {
268+ log.Fatal (err)
269+ }
270+ }
271+ ```
272+
273+ Multiple values need to be passed as separate, repeating flags, e.g. ` --greeting Hello --greeting Hola ` .
274+
233275#### Grouping
234276
235277You can associate a category for each flag to group them together in the help output, e.g:
You can’t perform that action at this time.
0 commit comments