-
Notifications
You must be signed in to change notification settings - Fork 112
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
Help text duplicated when using more than 1 CLI instance #1002
Comments
I have a very vague recollection of researching how to make a deep copy of a parser and finding that it was possible in Python 3.7+ (or something similar) but not beforehand. |
Yeah, inability to deep-copy an |
@kmvanbrunt #1005 appears to have fixed this, at least temporarily. Are we awaiting a more permanent fix? Or should this issue be closed? |
@tleonhardt The permanent fix needs to be in 2.0. We need a way to support instance-specific parsers and that will most likely be a breaking change. |
@anselor Do you have any thoughts on this issue? |
I'm sure I do I've just been busy with other more immediate deadlines and haven't had time to come back to this and other cmd2 stuff. |
@anselor and I agree the 2.0 release does not have to wait for this fix. The risk of someone using two cmd2 objects and editing common parsers between them is pretty low. |
@kmvanbrunt Is this fixed now? Or are we waiting on some better fix? |
Could this be avoided if the decorators accepted a argparser factory (a callable that returns an instance of argparser) so the instance is created when needed? |
I tried this today to be sure but I was pretty sure this suggestion by itself wouldn't work because the decorator, just like the the ArgumentParser instances, only runs once during the class declaration. I've been digging around the code a bit and I think may have a solution uses the factory suggestion while also maintaining backwards compatibility. I think what we need to do is, as a command is registered in the commandset (be it during construction or later) we need to at that point either clone the provided ArgumentParser or call the factory method and then store that in the Cmd or CommandSet instance. The innermost |
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
…rgumentParser or a factory callable that returns an ArgumentParser. Changed Cmd constructor to construct an instance-specific ArgumentParser using either the factory callable or by deep-copying the provided ArgumentParser. With this change a new argparse instance should be created for each instance of Cmd. Addresses #1002
With this program, run
alias -h
. The subcommand help gets repeated.Since the parsers (e.g.
Cmd.alias_parser
) are class objects, they get updated with each instantiation. This problem has existed since we added theargparse
decorators, but it's being exercised a bit more since we addedCommandSet
andas_subcommand_to
decorators. This specific issue of repeated text was introduced when cmd2.py started using theas_subcommand_to
decorator.For the 2.0 release, we need to find a way to make deep copies of the parsers and tie each copy to an instance. We won't have 1 parser attached to the functions anymore. Instead the decorators will need to retrieve the instance-specific parser.
The text was updated successfully, but these errors were encountered: