-
Notifications
You must be signed in to change notification settings - Fork 343
Add completion script generation #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This makes the ordering of names deterministic across program runs.
This lets CaseIterable types get completion values for free, and should let URL specify .files when someone adds ExpressibleByArgument conformance
This moves shell completion scripts further toward feature completeness: - auto-detecting the current user's shell - using patterns for file or directory completions - using a custom function for custom completions
ceb9494
to
5e988ae
Compare
We don't yet have the ability to define `--key [value]`-style args, so we need to fake this by checking two different command definitions.
736eda2
to
03c7aec
Compare
This moves from having a general file-matching pattern to just a list of valid extensions, which is simpler to implement across different shells.
8893ae5
to
02ec7e4
Compare
For example, `swift package ...` calls the `swift-package` executable. This has impacts on help, code completion scripts, etc.
18e4664
to
ec90064
Compare
@swift-ci Please test |
@swift-ci Please test |
When you say no automated way to test completions work, is this not possible with say opening a PTY and attempting at least some completions? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This adds support for generating shell completion scripts for tools built using
ArgumentParser
.Detailed Design
This adds a
CompletionKind
struct that you can specify when declaring an@Option
property:Types that conform to
ExpressibleByArgument
can also provide astatic var defaultCompletionKind: CompletionKind
to provide the completion kind when it's omitted from the property wrapper declaration.To generate completion scripts, you use the
--generate-completions
option on your command-line tool:You can generate completion scripts programmatically by calling the
completionScript(for:)
method on the rootParsableCommand
type for a command.Documentation Plan
Symbol documentation for all of the new additions, along with a new guide specifically about using, customizing, and installing completion scripts.
Test Plan
I've added unit tests for generating completion scripts with different completion parameters, as well as an integration test for the
math
command. I've also been testing this feature in the context of SwiftPM adoption of ArgumentParser. Unfortunately, we don't have an automated way to test that the completion scripts actually work properly, so that verification has been manual.Source Impact
No source impact for existing code.
Checklist