-
Notifications
You must be signed in to change notification settings - Fork 335
Commit bdb3b27
authored
Improve bash completion script generation (#735)
* Restrict access to symbols in BashCompletionsGenerator.swift.
* Use key path instead of closure in BashCompletionsGenerator.swift.
* Remove extraneous bash spacing.
* Do not indent bash cases.
Standardize bash indents.
* Do not prefix bash cases with an open parenthesis.
* Brace & quote bash variable uses.
* Remove extraneous bash blank line.
* Improve bash escaping.
* Improve bash $cur, $prev, & $COMPREPLY.
Use positional arguments passed by bash to the main completion function instead of reading from COMP_WORDS, as that can return the wrong info if completing an empty word before a non-empty word.
Make $cur & $prev local & readonly.
Remove unnecessary COMPREPLY=().
* Improve bash $SAP_SHELL & $SAP_SHELL_VERSION.
Make them local & readonly.
* Overhaul BashCompletionsGenerator.swift as [ParsableCommand.Type] extension.
Inline some single-use functions.
* Move bashValueCompletion(…) in BashCompletionsGenerator.swift.
Move from ArgumentDefinition extension to [ParsableCommand.Type] extension.
* Overhaul bash completion script generation:
Attempt to emulate the much more complete & correct zsh completion script.
Offer candidates for only the current positional / option value, not for all.
Generate completions for positionals the same as for option values.
Offer flags & options only if no prior option-terminator marker (a standalone --).
Offer flags & options only if current word starts with a -, or if there are no remaining positional parameters.
Parse options prior to subcommands later in the command line.
Offer flags & options only once.
Do not offer flags or options if the current word is an option value.
* Add default help to bash completions iff no existing help subcommand.
* Improve bash file & directory completions.
Do not split paths with spaces into separate completions.
Escape spaces in paths.
Append / to directory paths.
Do not use _filedir from bash-completions; use builtin bash constructs instead.
Fix broken existing escaping of single quotes in file extension filters.
More succinct & performant.
* Disable history ! in bash completion scripts.
* Do not include uppercased extensions in bash file(extensions:) completions.
That behavior was a bug, not a feature.
Released Swift Argument Parser documentation says:
"Complete file names with the specified extensions."
It does not mention including uppercase versions of the extensions.
None of the other shells include uppercase versions of extensions.
Why should uppercase versions be special? Why not case-insensitive matching? Why not lowercase versions? Etc.
Any config depending on this behavior won't match uppercase extensions without manually being reconfigured, but there are a ton of other bug fixes that can also break compatibility.
* Use single quoted string for bash list completions.
bash scripts now escape single quotes in list values.
Any existing list values with escapes that worked in double quotes will not work in the single quotes. But now:
- list values needn't be escaped
- unescaped double quotes in list values won't break the script
- $ & other characters won't interact with the shell, so, e.g., command substitutions cannot cause problems
* Allow bash list completions to contain spaces.
* Allow bash custom completions to contain spaces.
Properly refuses to complete when there are no completion candidates.
Still cannot complete to an empty string.
* bash custom completion of empty word followed by other words.
* Prevent bash shellCommand completion scripting from breaking scripts.
Eval the given command from a single-quoted string instead of running it directly in the shell.
* Allow bash shellCommand completions to contain spaces.
If existing shellCommand completions depend on spaces as completion delimiters, they will not work anymore. Newlines are now the only supported delimiters.
Resolve #734
* Use zip(…) to generate bash positional argument numbers.
* Rework bash positional case generation.
* Reverse the polarity of the neutron flow of the completions help subcommand detector.
* Rename flags & options vars to flagCompletions & optionCompletions, respectively, in BashCompletionsGenerator.swift.
* Remove TODO comments from generated bash completion scripts.
---------
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>1 parent 74f1f8c commit bdb3b27Copy full SHA for bdb3b27
File tree
4 files changed
+770
-386
lines changedFilter options
- Sources/ArgumentParser/Completions
- Tests
- ArgumentParserExampleTests/Snapshots
- ArgumentParserUnitTests/Snapshots
4 files changed
+770
-386
lines changed
0 commit comments