Add example app for suggestion in command
and further reduce example output diff potential
This commit is contained in:
parent
34eed95a8e
commit
9bd6349ed2
@ -126,15 +126,16 @@ func TestSuggestCommand(t *testing.T) {
|
|||||||
|
|
||||||
func ExampleApp_Suggest() {
|
func ExampleApp_Suggest() {
|
||||||
app := &App{
|
app := &App{
|
||||||
Name: "greet",
|
Name: "greet",
|
||||||
Suggest: true,
|
Suggest: true,
|
||||||
HideHelp: true,
|
HideHelp: true,
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
|
CustomAppHelpTemplate: "(this space intentionally left blank)\n",
|
||||||
Flags: []Flag{
|
Flags: []Flag{
|
||||||
&StringFlag{Name: "name", Value: "squirrel", Usage: "a name to say"},
|
&StringFlag{Name: "name", Value: "squirrel", Usage: "a name to say"},
|
||||||
},
|
},
|
||||||
Action: func(c *Context) error {
|
Action: func(cCtx *Context) error {
|
||||||
fmt.Printf("Hello %v\n", c.String("name"))
|
fmt.Printf("Hello %v\n", cCtx.String("name"))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -145,12 +146,46 @@ func ExampleApp_Suggest() {
|
|||||||
//
|
//
|
||||||
// Did you mean '--name'?
|
// Did you mean '--name'?
|
||||||
//
|
//
|
||||||
// NAME:
|
// (this space intentionally left blank)
|
||||||
// greet - A new cli application
|
}
|
||||||
//
|
|
||||||
// USAGE:
|
func ExampleApp_Suggest_command() {
|
||||||
// greet [global options] [arguments...]
|
app := &App{
|
||||||
//
|
Name: "greet",
|
||||||
// GLOBAL OPTIONS:
|
Suggest: true,
|
||||||
// --name value a name to say (default: "squirrel")
|
HideHelp: true,
|
||||||
|
HideHelpCommand: true,
|
||||||
|
CustomAppHelpTemplate: "(this space intentionally left blank)\n",
|
||||||
|
Flags: []Flag{
|
||||||
|
&StringFlag{Name: "name", Value: "squirrel", Usage: "a name to say"},
|
||||||
|
},
|
||||||
|
Action: func(cCtx *Context) error {
|
||||||
|
fmt.Printf("Hello %v\n", cCtx.String("name"))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Commands: []*Command{
|
||||||
|
{
|
||||||
|
Name: "neighbors",
|
||||||
|
CustomHelpTemplate: "(this space intentionally left blank)\n",
|
||||||
|
Flags: []Flag{
|
||||||
|
&BoolFlag{Name: "smiling"},
|
||||||
|
},
|
||||||
|
Action: func(cCtx *Context) error {
|
||||||
|
if cCtx.Bool("smiling") {
|
||||||
|
fmt.Println("😀")
|
||||||
|
}
|
||||||
|
fmt.Println("Hello, neighbors")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run([]string{"greet", "neighbors", "--sliming"})
|
||||||
|
// Output:
|
||||||
|
// Incorrect Usage: flag provided but not defined: -sliming
|
||||||
|
//
|
||||||
|
// Did you mean '--smiling'?
|
||||||
|
//
|
||||||
|
// (this space intentionally left blank)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user