diff --git a/docs/v2/images/custom-bash-autocomplete.gif b/docs/v2/images/custom-bash-autocomplete.gif new file mode 100644 index 0000000000..b6364f17b3 Binary files /dev/null and b/docs/v2/images/custom-bash-autocomplete.gif differ diff --git a/docs/v2/images/custom-zsh-autocomplete.gif b/docs/v2/images/custom-zsh-autocomplete.gif new file mode 100644 index 0000000000..58bf4189a2 Binary files /dev/null and b/docs/v2/images/custom-zsh-autocomplete.gif differ diff --git a/docs/v2/images/default-bash-autocomplete.gif b/docs/v2/images/default-bash-autocomplete.gif new file mode 100644 index 0000000000..f65b01f90a Binary files /dev/null and b/docs/v2/images/default-bash-autocomplete.gif differ diff --git a/docs/v2/images/default-zsh-autocomplete.gif b/docs/v2/images/default-zsh-autocomplete.gif new file mode 100644 index 0000000000..ead9115b5c Binary files /dev/null and b/docs/v2/images/default-zsh-autocomplete.gif differ diff --git a/docs/v2/manual.md b/docs/v2/manual.md index f3dea98abe..78a810072c 100644 --- a/docs/v2/manual.md +++ b/docs/v2/manual.md @@ -995,10 +995,75 @@ have a single leading `-` or this will result in failures. For example, ### Bash Completion You can enable completion commands by setting the `EnableBashCompletion` -flag on the `App` object. By default, this setting will only auto-complete to -show an app's subcommands, but you can write your own completion methods for -the App or its subcommands. +flag on the `App` object to `true`. By default, this setting will allow auto-completion +for an app's subcommands, but you can write your own completion methods for +the App or its subcommands as well. +#### Default auto-completion + +```go +package main +import ( + "fmt" + "log" + "os" + "github.com/urfave/cli" +) +func main() { + app := cli.NewApp() + app.EnableBashCompletion = true + app.Commands = []cli.Command{ + { + Name: "add", + Aliases: []string{"a"}, + Usage: "add a task to the list", + Action: func(c *cli.Context) error { + fmt.Println("added task: ", c.Args().First()) + return nil + }, + }, + { + Name: "complete", + Aliases: []string{"c"}, + Usage: "complete a task on the list", + Action: func(c *cli.Context) error { + fmt.Println("completed task: ", c.Args().First()) + return nil + }, + }, + { + Name: "template", + Aliases: []string{"t"}, + Usage: "options for task templates", + Subcommands: []cli.Command{ + { + Name: "add", + Usage: "add a new template", + Action: func(c *cli.Context) error { + fmt.Println("new task template: ", c.Args().First()) + return nil + }, + }, + { + Name: "remove", + Usage: "remove an existing template", + Action: func(c *cli.Context) error { + fmt.Println("removed task template: ", c.Args().First()) + return nil + }, + }, + }, + }, + } + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} +``` +![](/docs/v2/images/default-bash-autocomplete.gif) + +#### Custom auto-completion