MCPcopy
hub / github.com/urfave/cli / ExampleCommand_Run_mapValues

Function ExampleCommand_Run_mapValues

examples_test.go:481–510  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

479}
480
481func ExampleCommand_Run_mapValues() {
482 cmd := &cli.Command{
483 Name: "multi_values",
484 Flags: []cli.Flag{
485 &cli.StringMapFlag{Name: "stringMap"},
486 },
487 HideHelp: true,
488 Action: func(ctx context.Context, cmd *cli.Command) error {
489 for i, v := range cmd.FlagNames() {
490 fmt.Printf("%d-%s %#v\n", i, v, cmd.StringMap(v))
491 }
492 fmt.Printf("notfound %#v\n", cmd.StringMap("notfound"))
493 err := ctx.Err()
494 fmt.Println("error:", err)
495 return err
496 },
497 }
498
499 // Simulate command line arguments
500 os.Args = []string{
501 "multi_values",
502 "--stringMap", "parsed1=parsed two", "--stringMap", "parsed3=",
503 }
504
505 _ = cmd.Run(context.Background(), os.Args)
506 // Output:
507 // 0-stringMap map[string]string{"parsed1":"parsed two", "parsed3":""}
508 // notfound map[string]string(nil)
509 // error: <nil>
510}
511
512func ExampleBoolWithInverseFlag() {
513 flagWithInverse := &cli.BoolWithInverseFlag{

Callers

nothing calls this directly

Calls 3

FlagNamesMethod · 0.95
StringMapMethod · 0.95
RunMethod · 0.95

Tested by

no test coverage detected