| 510 | } |
| 511 | |
| 512 | func ExampleBoolWithInverseFlag() { |
| 513 | flagWithInverse := &cli.BoolWithInverseFlag{ |
| 514 | Name: "env", |
| 515 | } |
| 516 | |
| 517 | cmd := &cli.Command{ |
| 518 | Flags: []cli.Flag{ |
| 519 | flagWithInverse, |
| 520 | }, |
| 521 | Action: func(_ context.Context, cmd *cli.Command) error { |
| 522 | if flagWithInverse.IsSet() { |
| 523 | if cmd.Bool("env") { |
| 524 | fmt.Println("env is set") |
| 525 | } else { |
| 526 | fmt.Println("no-env is set") |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | return nil |
| 531 | }, |
| 532 | } |
| 533 | |
| 534 | _ = cmd.Run(context.Background(), []string{"prog", "--no-env"}) |
| 535 | |
| 536 | fmt.Println("flags:", len(flagWithInverse.Names())) |
| 537 | |
| 538 | // Output: |
| 539 | // no-env is set |
| 540 | // flags: 2 |
| 541 | } |
| 542 | |
| 543 | func ExampleCommand_Suggest() { |
| 544 | cmd := &cli.Command{ |