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

Function ExampleCommand_Suggest_command

examples_test.go:571–610  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

569}
570
571func ExampleCommand_Suggest_command() {
572 cmd := &cli.Command{
573 ErrWriter: os.Stdout,
574 Name: "greet",
575 Flags: []cli.Flag{
576 &cli.StringFlag{Name: "name", Value: "squirrel", Usage: "a name to say"},
577 },
578 Action: func(_ context.Context, cmd *cli.Command) error {
579 fmt.Printf("Hello %v\n", cmd.String("name"))
580 return nil
581 },
582 Commands: []*cli.Command{
583 {
584 Name: "neighbors",
585 HideHelp: true,
586 HideHelpCommand: true,
587 Suggest: true,
588 CustomHelpTemplate: "(this space intentionally left blank)\n",
589 Flags: []cli.Flag{
590 &cli.BoolFlag{Name: "smiling"},
591 },
592 Action: func(_ context.Context, cmd *cli.Command) error {
593 if cmd.Bool("smiling") {
594 fmt.Println("😀")
595 }
596 fmt.Println("Hello, neighbors")
597 return nil
598 },
599 },
600 },
601 }
602
603 if cmd.Run(context.Background(), []string{"greet", "neighbors", "--sliming"}) == nil {
604 fmt.Println("Expected error")
605 }
606 // Output:
607 // Incorrect Usage: flag provided but not defined: -sliming
608 //
609 // Did you mean "--smiling"?
610}

Callers

nothing calls this directly

Calls 3

StringMethod · 0.95
BoolMethod · 0.95
RunMethod · 0.95

Tested by

no test coverage detected