| 444 | } |
| 445 | |
| 446 | func ExampleCommand_Run_sliceValues() { |
| 447 | cmd := &cli.Command{ |
| 448 | Name: "multi_values", |
| 449 | Flags: []cli.Flag{ |
| 450 | &cli.StringSliceFlag{Name: "stringSlice"}, |
| 451 | &cli.FloatSliceFlag{Name: "float64Slice"}, |
| 452 | &cli.Int64SliceFlag{Name: "intSlice"}, |
| 453 | }, |
| 454 | HideHelp: true, |
| 455 | Action: func(ctx context.Context, cmd *cli.Command) error { |
| 456 | for i, v := range cmd.FlagNames() { |
| 457 | fmt.Printf("%d-%s %#v\n", i, v, cmd.Value(v)) |
| 458 | } |
| 459 | err := ctx.Err() |
| 460 | fmt.Println("error:", err) |
| 461 | return err |
| 462 | }, |
| 463 | } |
| 464 | |
| 465 | // Simulate command line arguments |
| 466 | os.Args = []string{ |
| 467 | "multi_values", |
| 468 | "--stringSlice", "parsed1,parsed2", "--stringSlice", "parsed3,parsed4", |
| 469 | "--float64Slice", "13.3,14.4", "--float64Slice", "15.5,16.6", |
| 470 | "--intSlice", "13,14", "--intSlice", "15,16", |
| 471 | } |
| 472 | |
| 473 | _ = cmd.Run(context.Background(), os.Args) |
| 474 | // Output: |
| 475 | // 0-stringSlice []string{"parsed1", "parsed2", "parsed3", "parsed4"} |
| 476 | // 1-float64Slice []float64{13.3, 14.4, 15.5, 16.6} |
| 477 | // 2-intSlice []int64{13, 14, 15, 16} |
| 478 | // error: <nil> |
| 479 | } |
| 480 | |
| 481 | func ExampleCommand_Run_mapValues() { |
| 482 | cmd := &cli.Command{ |