Refinements to removal of zsh hack

main
Dan Buch 2 years ago
parent e66ce91db1
commit e66017d73a
Signed by: meatballhat
GPG Key ID: A12F782281063434

@ -228,6 +228,7 @@ func ExampleApp_Run_subcommandNoAction() {
} }
func ExampleApp_Run_bashComplete_withShortFlag() { func ExampleApp_Run_bashComplete_withShortFlag() {
os.Setenv("SHELL", "bash")
os.Args = []string{"greet", "-", "--generate-bash-completion"} os.Args = []string{"greet", "-", "--generate-bash-completion"}
app := NewApp() app := NewApp()
@ -255,6 +256,7 @@ func ExampleApp_Run_bashComplete_withShortFlag() {
} }
func ExampleApp_Run_bashComplete_withLongFlag() { func ExampleApp_Run_bashComplete_withLongFlag() {
os.Setenv("SHELL", "bash")
os.Args = []string{"greet", "--s", "--generate-bash-completion"} os.Args = []string{"greet", "--s", "--generate-bash-completion"}
app := NewApp() app := NewApp()
@ -283,6 +285,7 @@ func ExampleApp_Run_bashComplete_withLongFlag() {
// --similar-flag // --similar-flag
} }
func ExampleApp_Run_bashComplete_withMultipleLongFlag() { func ExampleApp_Run_bashComplete_withMultipleLongFlag() {
os.Setenv("SHELL", "bash")
os.Args = []string{"greet", "--st", "--generate-bash-completion"} os.Args = []string{"greet", "--st", "--generate-bash-completion"}
app := NewApp() app := NewApp()
@ -315,7 +318,7 @@ func ExampleApp_Run_bashComplete_withMultipleLongFlag() {
} }
func ExampleApp_Run_bashComplete() { func ExampleApp_Run_bashComplete() {
// set args for examples sake os.Setenv("SHELL", "bash")
os.Args = []string{"greet", "--generate-bash-completion"} os.Args = []string{"greet", "--generate-bash-completion"}
app := &App{ app := &App{

@ -1,16 +1,20 @@
#compdef $PROG #compdef $PROG
local -a opts _cli_zsh_autocomplete() {
local cur local -a opts
cur=${words[-1]} local cur
if [[ "$cur" == "-"* ]]; then cur=${words[-1]}
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") if [[ "$cur" == "-"* ]]; then
else opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") else
fi opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}")
fi
if [[ "${opts[1]}" != "" ]]; then if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts _describe 'values' opts
else else
_files _files
fi fi
}
compdef _cli_zsh_autocomplete $PROG

@ -1165,10 +1165,10 @@ func main() {
``` ```
#### ZSH Support #### ZSH Support
Auto-completion for ZSH is also supported using the `autocomplete/zsh_autocomplete` Auto-completion for ZSH is also supported using the `autocomplete/zsh_autocomplete`
file included in this repo. One environment variable is used, `PROG`. Set file included in this repo. One environment variable is used, `PROG`. Set
`PROG` to the program name as before, and then `source path/to/autocomplete/zsh_autocomplete`. `PROG` to the program name as before, and then `source path/to/autocomplete/zsh_autocomplete`.
Adding the following lines to your ZSH configuration file (usually `.zshrc`) Adding the following lines to your ZSH configuration file (usually `.zshrc`)
will allow the auto-completion to persist across new shells: will allow the auto-completion to persist across new shells:
``` ```

@ -1040,12 +1040,16 @@ func TestHideHelpCommand_WithSubcommands(t *testing.T) {
} }
func TestDefaultCompleteWithFlags(t *testing.T) { func TestDefaultCompleteWithFlags(t *testing.T) {
origEnv := os.Environ()
origArgv := os.Args origArgv := os.Args
t.Cleanup(func() { t.Cleanup(func() {
os.Args = origArgv os.Args = origArgv
resetEnv(origEnv)
}) })
os.Setenv("SHELL", "bash")
for _, tc := range []struct { for _, tc := range []struct {
name string name string
c *Context c *Context

Loading…
Cancel
Save