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

Function ExampleCommand_Suggest

examples_test.go:543–569  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

541}
542
543func ExampleCommand_Suggest() {
544 cmd := &cli.Command{
545 Name: "greet",
546 ErrWriter: os.Stdout,
547 Suggest: true,
548 HideHelp: false,
549 HideHelpCommand: true,
550 CustomRootCommandHelpTemplate: "(this space intentionally left blank)\n",
551 Flags: []cli.Flag{
552 &cli.StringFlag{Name: "name", Value: "squirrel", Usage: "a name to say"},
553 },
554 Action: func(_ context.Context, cmd *cli.Command) error {
555 fmt.Printf("Hello %v\n", cmd.String("name"))
556 return nil
557 },
558 }
559
560 if cmd.Run(context.Background(), []string{"greet", "--nema", "chipmunk"}) == nil {
561 fmt.Println("Expected error")
562 }
563 // Output:
564 // Incorrect Usage: flag provided but not defined: -nema
565 //
566 // Did you mean "--name"?
567 //
568 // (this space intentionally left blank)
569}
570
571func ExampleCommand_Suggest_command() {
572 cmd := &cli.Command{

Callers

nothing calls this directly

Calls 2

StringMethod · 0.95
RunMethod · 0.95

Tested by

no test coverage detected