python - Argparse: parse multiple subcommands -


did research, couldn't find working solution. i'm trying parse following command line, 'test' , 'train' 2 independent subcommands each having distinct arguments:

./foo.py train -a 1 -b 2  ./foo.py test  -a 3 -c 4 ./foo.py train -a 1 -b 2 test -a 3 -c 4 

i've been trying using 2 subparsers ('test','train') seems 1 can parsed @ time. great have subparsers parents of main parser such that, e.g. command '-a' doesn't have added both subparsers 'train' , 'test'

any solution?

this has been asked before, though i'm not sure best way of finding questions.

the whole subparser mechanism designed 1 such command. there several things note:

  • add_subparsers creates positional argument; unlike optionals `positional acts once.

  • 'add_subparsers' raises error if invoke several times

  • the parsing built around 1 such call

one work around we've proposed in past 'nested' or 'recursive' subparers. in other words train setup takes subparser. there's complication whether subparsers required or not.

or can detect , call multiple parsers, bypassing subparser mechanism.

from sidebar

multiple invocation of same subcommand in single command line

and

parse multiple subcommands in python simultaneously or other way group parsed arguments


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -