Skip to content
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

fish/complete: Generate helper functions to check for subcommands #5568

Merged
merged 9 commits into from
Jul 11, 2024

Conversation

tesuji
Copy link
Contributor

@tesuji tesuji commented Jul 5, 2024

As guided by fish's maintainer, to handle nested subcommands, we try to generate 3 new functions for completion scripts:

  • __fish_{name}_global_optspecs will gather global option specifications,
  • __fish_{name}_needs_command, with rustup \t, used to check for rustup
  • __fish_{name}_using_subcommand show, with rustup show \t, check if current cmd is show

This pattern is popular within fish-shell repository, for some commands:

This is complicated, as stated by fish's maintainers. Let's hope the new fish proposal will improve things.

This PR contains a HACK: Assuming subcommands are only nested less than 3 levels as more than that is unwieldy and takes more effort to support. For example, rustup toolchain help install is the longest valid command line of rustup that uses nested subcommands, and it cannot receive any flags to it.

@tesuji tesuji force-pushed the fish-nested-sub branch 3 times, most recently from a4b755c to fc5fbe1 Compare July 5, 2024 21:00
@tesuji tesuji marked this pull request as ready for review July 5, 2024 21:00
@tesuji tesuji changed the title fish/complete: Generate helpers script to check for subcommands fish/complete: Generate helper functions to check for subcommands Jul 5, 2024
@tesuji tesuji force-pushed the fish-nested-sub branch 3 times, most recently from f1182cb to 1d94540 Compare July 6, 2024 00:57
Nested subcommand more than 3 levels is not practical in public.
Take rustup for example, `rustup toolchain install <version>`,
there is only 3 levels of nested subcommands. But there is also
the case of `rustup help toolchain install`, or `rustup toolchain help install`.
@tesuji
Copy link
Contributor Author

tesuji commented Jul 9, 2024

Alright, thanks for bearing with my unclear explanation. I tried to do better with new pushed commits.
Let me know if you have any questions.

@epage epage merged commit 280fb4e into clap-rs:master Jul 11, 2024
21 of 22 checks passed
@epage
Copy link
Member

epage commented Jul 11, 2024

Thanks for working on this and your patience through the rounds of feedback!

@tesuji tesuji deleted the fish-nested-sub branch July 11, 2024 03:39
@tesuji
Copy link
Contributor Author

tesuji commented Jul 11, 2024

I'm very thankful for your guide/help through the code, raising helpful questions that I explained very poorly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants