-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
Clap Version
3.2.6
Describe your use case
I'm writing a Clap CLI that will eventually replace an existing Python CLI we have. The goal is to have this new CLI be the default one used and have it support fallback to the Python CLI for subcommands that are not yet implemented. Ideally, I'd like to dynamically generate the fallback subcommands as to not require any code changes / manually syncing between the Python version and the Clap/Rust version.
While .allow_external_subcommands gets me sort of there, but it gets messy in this instance:
- Python CLI has command
foo generate barandfoo read bar - New Clap CLI has command
foo generate bazandfoo read bazbut notfoo generate barorfoo read bar.
Currently, we'd have to add .allow_external_subcommands to both the generate subcommand and read subcommand, and implement duplicate matching logic for both. This also can't be done dynamically and we'd have to update the Rust/Clap CLI if there are any changes to the Python CLI.
What I'd ideally like is, traverse an existing Command we have (i.e. made with the Derive API) and insert subcommands found from the Python CLI command tree (which I can already generate) that are not in our current Command struct. This part is currently not possible as there's no way to modify existing subcommands as far as I'm aware. I can then have logic with get_matches() to detect when a fallback subcommand is used.
Describe the solution you'd like
There's already an API to modify existing args, mut_arg so I think the best solution would just be to duplicate this logic in a mut_subcommand method.
Alternatives, if applicable
No response
Additional Context
No response