diff --git a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift index c42ca5ac..3e3c168c 100644 --- a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift @@ -143,15 +143,15 @@ extension [ParsableCommand.Type] { let line: String switch arg.names.count { case 0: - line = "" + line = arg.help.options.contains(.isRepeating) ? "*" : "" case 1: line = """ - \(arg.isRepeatableOption ? "*" : "")\(arg.names[0].synopsisString)\(arg.zshCompletionAbstract) + \(arg.isRepeatingOption ? "*" : "")\(arg.names[0].synopsisString)\(arg.zshCompletionAbstract) """ default: let synopses = arg.names.map { $0.synopsisString } line = """ - \(arg.isRepeatableOption ? "*" : "(\(synopses.joined(separator: " ")))")'\ + \(arg.isRepeatingOption ? "*" : "(\(synopses.joined(separator: " ")))")'\ {\(synopses.joined(separator: ","))}\ '\(arg.zshCompletionAbstract) """ @@ -251,9 +251,9 @@ extension String { } extension ArgumentDefinition { - /// - returns: `true` if `self` is an option and can be tab-completed multiple times in one command line. + /// - returns: `true` if `self` is a flag or an option and can be tab-completed multiple times in one command line. /// For example, `ssh` allows the `-L` option to be given multiple times, to establish multiple port forwardings. - fileprivate var isRepeatableOption: Bool { + fileprivate var isRepeatingOption: Bool { guard case .named(_) = kind, help.options.contains(.isRepeating) diff --git a/Tests/ArgumentParserExampleTests/Snapshots/testMathZshCompletionScript().zsh b/Tests/ArgumentParserExampleTests/Snapshots/testMathZshCompletionScript().zsh index e772eb5a..07abcf40 100644 --- a/Tests/ArgumentParserExampleTests/Snapshots/testMathZshCompletionScript().zsh +++ b/Tests/ArgumentParserExampleTests/Snapshots/testMathZshCompletionScript().zsh @@ -73,7 +73,7 @@ _math_add() { local -i ret=1 local -ar arg_specs=( '(--hex-output -x)'{--hex-output,-x}'[Use hexadecimal notation for the result.]' - ':values:' + '*:values:' '--version[Show the version.]' '(-h --help)'{-h,--help}'[Show help information.]' ) @@ -86,7 +86,7 @@ _math_multiply() { local -i ret=1 local -ar arg_specs=( '(--hex-output -x)'{--hex-output,-x}'[Use hexadecimal notation for the result.]' - ':values:' + '*:values:' '--version[Show the version.]' '(-h --help)'{-h,--help}'[Show help information.]' ) @@ -130,7 +130,7 @@ _math_stats_average() { local -ar __math_stats_average_kind=('mean' 'median' 'mode') local -ar arg_specs=( '--kind[The kind of average to provide.]:kind:{__math_complete "${__math_stats_average_kind[@]}"}' - ':values:' + '*:values:' '--version[Show the version.]' '(-h --help)'{-h,--help}'[Show help information.]' ) @@ -142,7 +142,7 @@ _math_stats_average() { _math_stats_stdev() { local -i ret=1 local -ar arg_specs=( - ':values:' + '*:values:' '--version[Show the version.]' '(-h --help)'{-h,--help}'[Show help information.]' ) @@ -158,7 +158,7 @@ _math_stats_quantiles() { ':one-of-four:{__math_complete "${math_stats_quantiles_one_of_four[@]}"}' ':custom-arg:{__math_custom_complete ---completion stats quantiles -- customArg "${current_word_index}" "$(__math_cursor_index_in_current_word)"}' ':custom-deprecated-arg:{__math_custom_complete ---completion stats quantiles -- customDeprecatedArg}' - ':values:' + '*:values:' '--file:file:_files -g '\''*.txt *.md'\''' '--directory:directory:_files -/' '--shell:shell:{local -a list;list=(${(f)"$(head -100 /usr/share/dict/words | tail -50)"});_describe -V "" list}' @@ -175,7 +175,7 @@ _math_stats_quantiles() { _math_help() { local -i ret=1 local -ar arg_specs=( - ':subcommands:' + '*:subcommands:' '--version[Show the version.]' ) _arguments -w -s -S : "${arg_specs[@]}" && ret=0 diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh b/Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh index a316b35e..0a1b0876 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh +++ b/Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh @@ -109,7 +109,7 @@ _base-test_escaped-command() { _base-test_help() { local -i ret=1 local -ar arg_specs=( - ':subcommands:' + '*:subcommands:' ) _arguments -w -s -S : "${arg_specs[@]}" && ret=0