clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
14.14k stars 1.03k forks source link

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

Closed tesuji closed 2 months ago

tesuji commented 3 months ago

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

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 commented 2 months ago

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 commented 2 months ago

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

tesuji commented 2 months ago

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