Merge pull request #498 from urfave/merging-jereksel-zsh
Merging #489 (plus hack)
This commit is contained in:
commit
d4bf9ce860
38
app_test.go
38
app_test.go
@ -258,6 +258,44 @@ func ExampleApp_Run_bashComplete() {
|
|||||||
// h
|
// h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleApp_Run_zshComplete() {
|
||||||
|
// set args for examples sake
|
||||||
|
os.Args = []string{"greet", "--generate-bash-completion"}
|
||||||
|
os.Setenv("_CLI_ZSH_AUTOCOMPLETE_HACK", "1")
|
||||||
|
|
||||||
|
app := NewApp()
|
||||||
|
app.Name = "greet"
|
||||||
|
app.EnableBashCompletion = true
|
||||||
|
app.Commands = []Command{
|
||||||
|
{
|
||||||
|
Name: "describeit",
|
||||||
|
Aliases: []string{"d"},
|
||||||
|
Usage: "use it to see a description",
|
||||||
|
Description: "This is how we describe describeit the function",
|
||||||
|
Action: func(c *Context) error {
|
||||||
|
fmt.Printf("i like to describe things")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
Name: "next",
|
||||||
|
Usage: "next example",
|
||||||
|
Description: "more stuff to see when generating bash completion",
|
||||||
|
Action: func(c *Context) error {
|
||||||
|
fmt.Printf("the next example")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run(os.Args)
|
||||||
|
// Output:
|
||||||
|
// describeit:use it to see a description
|
||||||
|
// d:use it to see a description
|
||||||
|
// next:next example
|
||||||
|
// help:Shows a list of commands or help for one command
|
||||||
|
// h:Shows a list of commands or help for one command
|
||||||
|
}
|
||||||
|
|
||||||
func TestApp_Run(t *testing.T) {
|
func TestApp_Run(t *testing.T) {
|
||||||
s := ""
|
s := ""
|
||||||
|
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
autoload -U compinit && compinit
|
_cli_zsh_autocomplete() {
|
||||||
autoload -U bashcompinit && bashcompinit
|
|
||||||
|
|
||||||
script_dir=$(dirname $0)
|
local -a opts
|
||||||
source ${script_dir}/bash_autocomplete
|
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
|
||||||
|
|
||||||
|
_describe 'values' opts
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
compdef _cli_zsh_autocomplete $PROG
|
||||||
|
10
help.go
10
help.go
@ -158,8 +158,14 @@ func DefaultAppComplete(c *Context) {
|
|||||||
if command.Hidden {
|
if command.Hidden {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, name := range command.Names() {
|
if os.Getenv("_CLI_ZSH_AUTOCOMPLETE_HACK") == "1" {
|
||||||
fmt.Fprintln(c.App.Writer, name)
|
for _, name := range command.Names() {
|
||||||
|
fmt.Fprintf(c.App.Writer, "%s:%s\n", name, command.Usage)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, name := range command.Names() {
|
||||||
|
fmt.Fprintf(c.App.Writer, "%s\n", name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user