Commit 91af755
authored
Improve fish completion script generation (#738)
* Improve fish escaping.
* Escape backslashes for fish single-quoted strings.
If someone already escapes backslashes for such strings, this will
cause an issue, but no one should be required to go to the trouble
to manually escape backslashes in their strings, especially since
the requirement isn't documented or normal.
If someone doesn't escape backslashes, then that can break then old
version of the script.
* Output fish functions via one Swift multiline string.
* Join fish short flags/options.
* Replace fish double quotes with single quotes.
* Use option terminator in each call to string split in fish completion.
* Add default help to fish completions iff no existing help subcommand.
* Rename fish variables.
* Rename fish functions & associated Swift functions & variables.
* Inline single-use Swift variables in FishCompletionsGenerator.swift.
* Use separator in FishCompletionsGenerator.swift.
* Overhaul FishCompletionsGenerator.swift as [ParsableCommand.Type]
extension.
* Move argumentSegments(…) in FishCompletionsGenerator.swift.
* Fix fish file, directory, shell command & custom Swift call
completions.
* Properly complete fish positionals.
Fix custom completion of empty argument.
Associate a description with a fish completion iff it's a
flag/option or a subcommand.
* Improve custom completion args for fish 4+.
* Fix switch end keyword bugs in _swift_*_commands_and_positionals fish
functions.
* Lowercase fish variables that were once global but that are now local.
* Use double-quoted variable instead of `string join ''` in fish
completion scripts.
* Use option terminator in call to string split in fish completion.
* Pass each fish option spec to _swift_*_commands_and_positionals
functions as a separate argument.
* Overhaul generated fish completion scripts:
Allow positionals & subcommands on the same (sub)command.
Don't use `-r` for complete calls for positionals.
Use `-\(r)fka ''` for positionals or option values with no
completion candidates.
Allow option_specs elements to contain spaces.
Explicitly scope variables.
Rename functions.
Prevent odd characters in (sub)command names from breaking the
script in some places.
Prevent missing data from breaking if tests.
* Backwards compatibility in fish completion scripts with fish 3.3.x-
Change set -f to set -l.
Replace $(…) with (…) command substitutions.
* Change fish function prefixes from `_swift_` to `__` to align with
other shells.1 parent cf4c472 commit 91af755
File tree
4 files changed
+456
-254
lines changed- Sources/ArgumentParser/Completions
- Tests
- ArgumentParserExampleTests/Snapshots
- ArgumentParserUnitTests/Snapshots
4 files changed
+456
-254
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
0 commit comments