Reputation: 33225
What I mean by multiple level arguments is something like svn help
, after parsing the svn help
part, the following word is considered argument to help
the subcommand.
Is it possible to set this up with optparse
?
Upvotes: 4
Views: 1769
Reputation: 6797
argparse support sub-commands : http://docs.python.org/library/argparse.html#sub-commands optparse is deprecated in favor of argparse since python 2.7
Upvotes: 2
Reputation: 1467
According to the python docs, optparse is now considered as deprecated, and won't be developed further; therefore i would strongly suggest you to use the module argparse, whith which you can create "multiple level" arguments.
import argparse
parser = argparse.ArgumentParser()
# Init sub-command
parser_init = subparsers.add_parser('init', help='initialize the things')
parser_init.add_argument(...)
# Help sub-command
parser_help = subparsers.add_parser('help', help='help me!')
parser_help.add_argument(...)
Upvotes: 6