★ wanayoo — archive 1999 https://github.com/python-cmd2/cmd2/issues/1002Nouvelle recherche | Portail wanayoo
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

Help text duplicated when using more than 1 CLI instance #1002

Open
kmvanbrunt opened this issue Sep 28, 2020 · 2 comments
Open

Help text duplicated when using more than 1 CLI instance #1002

kmvanbrunt opened this issue Sep 28, 2020 · 2 comments
Labels
Milestone

Comments

@kmvanbrunt
Copy link
Member

@kmvanbrunt kmvanbrunt commented Sep 28, 2020

import sys
from cmd2 import cmd2

instance_1 = cmd2.Cmd()
instance_2 = cmd2.Cmd()
sys.exit(instance_2.cmdloop())

With this program, run alias -h. The subcommand help gets repeated.

  SUBCOMMAND
    create    create or overwrite an alias
    delete    delete aliases
    list      delete aliases
    create    create or overwrite an alias
    delete    delete aliases
    list      delete aliases

Since the parsers (e.g. Cmd.alias_parser) are class objects, they get updated with each instantiation. This problem has existed since we added the argparse decorators, but it's being exercised a bit more since we added CommandSet and as_subcommand_to decorators. This specific issue of repeated text was introduced when cmd2.py started using the as_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.

@kmvanbrunt kmvanbrunt added this to the 2.0.0 milestone Sep 28, 2020
@tleonhardt
Copy link
Member

@tleonhardt tleonhardt commented Sep 28, 2020

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.

@tleonhardt
Copy link
Member

@tleonhardt tleonhardt commented Sep 28, 2020

Yeah, inability to deep-copy an ArgumentParser was fixed in Python 3.7. The context is in older issue #522

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.