-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(complete): generate completions for visible aliases #5476
Merged
Conversation
This file contains 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
epage
reviewed
Apr 29, 2024
epage
reviewed
Apr 29, 2024
Re: linter error. Commit subject max line length of 50 is brutal, even |
I fixed the linter issues, and implemented support for all shells. @epage is there something you'd like me to do here, or something I can do to make it easier for you to review it? Many thanks. |
Fixing the iteration over all_subcommands in zsh.rs. We deduplicate values on (sc_name, bin_name) keys, but then only iterate on bin_name. This doesn't cause problems now, since all bin names seem to be unique. However, without fixing this, the next commit would have started generating duplicated functions with same names. For example, with an #[long = "foo", visible_alias = "bar"] subcommand, we'll end up with 2 pairs: [("foo", "foo"), ("bar", "foo")]. Before this commit, we would have ended up generating _my-app__foo_commands() functions. These functions should have identical content, so it is not an error, just an inefficiency that we can fix.
Let's generate autocompletions for aliased subcommands. $ source before.zsh $ clap-test [TAB] <- gives me "foo bar --" $ clap-test foo [TAB] <- gives me "--my-flag" $ clap-test bar [TAB] <- no reaction $ source after.zsh $ clap-test [TAB] <- gives me "foo bar --" $ clap-test foo [TAB] <- gives me "--my-flag" $ clap-test bar [TAB] <- gives me "--my-flag"
Thanks! |
facebook-github-bot
pushed a commit
to facebookincubator/below
that referenced
this pull request
Jun 10, 2024
Summary: Upgrading clap to new version (released yesterday). My motivation for doing it now is that my PR clap-rs/clap#5476 has been released as part of this release, which should fix autocompletion for all CLIs using `visible_alias` option. Reviewed By: ukautz Differential Revision: D58283249 fbshipit-source-id: 4a48e86c47519431913c34880a132049b5522e7b
facebook-github-bot
pushed a commit
to facebookincubator/antlir
that referenced
this pull request
Jun 10, 2024
Summary: Upgrading clap to new version (released yesterday). My motivation for doing it now is that my PR clap-rs/clap#5476 has been released as part of this release, which should fix autocompletion for all CLIs using `visible_alias` option. Test Plan: ``` $ fbcode/common/rust/tools/reindeer/vendor ... 33 vulnerabilities, 1 warnings in 2989 packages ... 03:09:07 -07:00 INFO Successfully generated 2317 Cargo.toml and 456 additional files and stored them on disk $ fbcode/common/rust/tools/scripts/third-party-check.sh BUILD SUCCEEDED x5 $ fbcode/common/rust/tools/scripts/check_all.sh no errors for first 15 minutes, then buck died Command failed: Failed to connect to buck daemon. Try running `buck2 kill` and your command afterwards. Alternatively, try running `rm -rf ~/.buck/buckd` and your command afterwards ``` Testing if my PR clap-rs/clap#5476 works in fbcode: ```name=Before $ faceboot3 --help ... boot-from-network Creates, renders and activates the config, making a host boot from network [aliases: net, create-render-and-activate-config] ... $ faceboot3 boot-from-network [TAB] # autocompletes in zsh, fish and bash corp-provisioning (Boot using faceboot2 FacebootOptions) help (Print this message or the help of the given subcommand(s)) legacy-from-faceboot-options (Boot using faceboot2 FacebootOptions) legacy-from-metalos-config-url (Boot using MetalOS MultiConfig) …and 7 more rows $ faceboot3 net [TAB] # autocompletes in bash, nothing happens in zsh, fish starts suggesting files and directories in current directory ``` ```name=After $ buck2 build fbcode//syseng/faceboot3/cli:cli-completions.zsh fbcode//syseng/faceboot3/cli:cli-completions.bash fbcode//syseng/faceboot3/cli:cli-completions.fish --show-full-output fbcode//syseng/faceboot3/cli:cli-completions.bash /data/users/pzmarzly/fbsource/buck-out/v2/gen/fbcode/767cf7b4a84025eb/syseng/faceboot3/cli/__cli-completions.bash__/out/cli-completions.bash fbcode//syseng/faceboot3/cli:cli-completions.fish /data/users/pzmarzly/fbsource/buck-out/v2/gen/fbcode/767cf7b4a84025eb/syseng/faceboot3/cli/__cli-completions.fish__/out/cli-completions.fish fbcode//syseng/faceboot3/cli:cli-completions.zsh /data/users/pzmarzly/fbsource/buck-out/v2/gen/fbcode/767cf7b4a84025eb/syseng/faceboot3/cli/__cli-completions.zsh__/out/cli-completions.zsh $ sudo cp /data/users/pzmarzly/fbsource/buck-out/v2/gen/fbcode/767cf7b4a84025eb/syseng/faceboot3/cli/__cli-completions.bash__/out/cli-completions.bash /usr/share/bash-completion/completions/faceboot3 $ sudo cp /data/users/pzmarzly/fbsource/buck-out/v2/gen/fbcode/767cf7b4a84025eb/syseng/faceboot3/cli/__cli-completions.fish__/out/cli-completions.fish /etc/fish/completions/faceboot3.fish $ sudo cp /data/users/pzmarzly/fbsource/buck-out/v2/gen/fbcode/767cf7b4a84025eb/syseng/faceboot3/cli/__cli-completions.zsh__/out/cli-completions.zsh /usr/share/zsh/site-functions/_faceboot3 $ faceboot3 boot-from-network [TAB] # autocompletes in zsh, fish and bash $ faceboot3 net [TAB] # autocompletes in zsh, fish and bash ``` {P1400427477} {P1400437414} {P1400427342} Reviewed By: ukautz Differential Revision: D58283249 fbshipit-source-id: 4a48e86c47519431913c34880a132049b5522e7b
facebook-github-bot
pushed a commit
to facebookincubator/reindeer
that referenced
this pull request
Jun 10, 2024
Summary: Upgrading clap to new version (released yesterday). My motivation for doing it now is that my PR clap-rs/clap#5476 has been released as part of this release, which should fix autocompletion for all CLIs using `visible_alias` option. Reviewed By: ukautz Differential Revision: D58283249 fbshipit-source-id: 4a48e86c47519431913c34880a132049b5522e7b
facebook-github-bot
pushed a commit
to facebookexperimental/rust-shed
that referenced
this pull request
Jun 10, 2024
Summary: Upgrading clap to new version (released yesterday). My motivation for doing it now is that my PR clap-rs/clap#5476 has been released as part of this release, which should fix autocompletion for all CLIs using `visible_alias` option. Reviewed By: ukautz Differential Revision: D58283249 fbshipit-source-id: 4a48e86c47519431913c34880a132049b5522e7b
facebook-github-bot
pushed a commit
to facebook/sapling
that referenced
this pull request
Jun 10, 2024
Summary: Upgrading clap to new version (released yesterday). My motivation for doing it now is that my PR clap-rs/clap#5476 has been released as part of this release, which should fix autocompletion for all CLIs using `visible_alias` option. Reviewed By: ukautz Differential Revision: D58283249 fbshipit-source-id: 4a48e86c47519431913c34880a132049b5522e7b
facebook-github-bot
pushed a commit
to facebook/hhvm
that referenced
this pull request
Jun 10, 2024
Summary: Upgrading clap to new version (released yesterday). My motivation for doing it now is that my PR clap-rs/clap#5476 has been released as part of this release, which should fix autocompletion for all CLIs using `visible_alias` option. Reviewed By: ukautz Differential Revision: D58283249 fbshipit-source-id: 4a48e86c47519431913c34880a132049b5522e7b
nardoor
added a commit
to rustic-rs/rustic_core
that referenced
this pull request
Sep 5, 2024
- visible_alias is completed by `clap_complete`: - https://docs.rs/clap_complete/latest/clap_complete/aot/utils/fn.longs_and_visible_aliases.html?search=alias - clap-rs/clap#5476
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.
Fixes #4265
Closes #5412
This PR picks up work from #5412 to get it to a merge-able state.
I'm splitting the work into 2 standalone commits (all tests pass on both of them), to make it easier to review. I leave it up to you whether to merge them in or squash them into one.
Commit 1. Fixing the iteration over
all_subcommands
inzsh.rs
. We deduplicate values on(sc_name, bin_name)
keys, but then only iterate onbin_name
. This doesn't cause problems now, since all bin names seem to be unique. However, without fixing this, the second commit would have started generating duplicated functions with same names.Commit 2. Starting to generate autocompletions for aliased subcommands. This is taking the code from #5412 and updating it to latest changes.
Testing the change
Adapting the test code from #4265's first comment:
After making this change to clap_complete: