python - How do I check for a particular subparser? -
how check particular subparser?
import argparse if __name__ == "__main__": mainparser = argparse.argumentparser() submainadder = mainparser.add_subparsers(title='subcommands') parser_ut = submainadder.add_parser('unittest') stuff = mainparser.parse_args() # if 'unittest' selected: # do_things()
maybe ?
import argparse def do_things(args): print args # stuff mainparser = argparse.argumentparser() submainadder = mainparser.add_subparsers(title='subcommands') parser_ut = submainadder.add_parser('unittest') parser_ut.set_defaults(func=do_things) if __name__ == "__main__": stuff = mainparser.parse_args() stuff.func(stuff)
more explanations can found here:
Comments
Post a Comment