[Python] Bug or intended behavior on cmd2.argparse_custom.Cmd2ArgumentParser()

Discussão em 'Python' iniciado por Stack, Abril 2, 2025.

  1. Stack

    Stack Membro Participativo

    What I have when creating a parser based off of cmd.cmd2 for a program here is the relevant code

    parser = cmd2.argparse_custom.Cmd2ArgumentParser(description='open', add_help=False)
    open_mission_args.add_argument(
    '-o', '--open',
    action='store',
    type=str,
    metavar='NAME',
    default='',
    dest='open',
    help='create and open new mission'
    )


    Basically I want to set the name with running myprogram --open=<my_name> for my name I have to have it support all names with alphanumeric characters, hyphens, and underscores. Everything works except myprogram --open=-- it is parsing this as [] I am assume it thinks I am starting a new argument is this a bug I thought the type=str, argument took care of this.

    Edit the only thing I can think of that would work is nargs=argparse.REMAINDER but that would require post parsing which I don't want to do.

    Continue reading...

Compartilhe esta Página