Skip to content

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

Closed
@kmvanbrunt

Description

@kmvanbrunt
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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions