Refinements to removal of zsh hack

This commit is contained in:
Dan Buch 2022-05-22 09:07:03 -04:00
parent e66ce91db1
commit e66017d73a
Signed by: meatballhat
GPG Key ID: A12F782281063434
4 changed files with 29 additions and 18 deletions

View File

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

View File

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

View File

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