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
Add ability to remove a subcommand #4927
Comments
Could you expand on the use case for why commands are being added and removed during the lifetime of the REPL? |
Sure, picture an interactive CLI with a plugin system:
An alternative design could be:
But this has the issue where switching back and forth between plugin commands is more tedious for the user (ideally user can load multiple plugins into namespace at once) Another alternative would be to allow multiple at once:
|
Or reference similar functionality in popular python module here: https://cmd2.readthedocs.io/en/stable/features/modular_commands.html |
This isn't the right approach with clap's design. clap expects everything to be added and then "builds". Once the build happens, changes shouldn't be made (I'd like to enforce this within the type system but haven't found a satisfactory design yet). Using this in a REPL to add / remove commands implies an existing instance is being reused. As an alternative, you could recreate your For |
Please complete the following tasks
Clap Version
master
Describe your use case
Basically I am trying to make an interactive REPL
I decided to originally follow from the recipe provided in the cookbook, basically have a root command set with
multicall
and I all commands in the REPL are implemented as subcommands.However, when the commands are the REPL are dynamic, I can add commands easily but removing commands that are no longer requires rebuilding the entire
Command
struct with the desired subcommand missing, which is rather tedious.Describe the solution you'd like
I just took the
mut_subcommand
function, copied it, and modified it to aremove_subcommand
function that has the same functionality except without the callback and without placing a subcommand back intoself.subcommands
Alternatives, if applicable
The other option I considered was modifying the
subcommand
function that followed the builder pattern, but since I'm not sure why you would need to remove a command in a builder pattern, I thought it was easier to modify the struct rather than create a new one.Additional Context
No response
The text was updated successfully, but these errors were encountered: