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

Function ExampleBoolWithInverseFlag

examples_test.go:512–541  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

510}
511
512func 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
543func ExampleCommand_Suggest() {
544 cmd := &cli.Command{

Callers

nothing calls this directly

Calls 4

IsSetMethod · 0.95
BoolMethod · 0.95
RunMethod · 0.95
NamesMethod · 0.95

Tested by

no test coverage detected