parser_a = subparsers.add_parser( 'sync', help='Sync the database to the most recent version.') parser_a.add_argument( '--version', nargs='?', metavar='<version>', default=None, help='Database version') parser_a.set_defaults(cmd='sync')
When I call the 'sync' command defined above, I'd expect the '--version' parameter to be handled by that parser. However, it seems the root parser handles this instead:
I'm reworking some code to use cliff. I've defined a custom Command:
class ApiDbCommands( Command) :
"""Class for managing the api database."""
def get_parser(self, prog_name): ands, self).get_ parser( prog_name)
parser = super(ApiDbComm
return parser
def sync(self, version=None):
print( 'syncing v%s' % version)
def take_action(self, parsed_args): parsed_ args, 'cmd', None)
cmd = getattr(
if cmd == 'sync':
self. sync(parsed_ args.version)
This is registered in the app, per the example in the docs:
COMMANDS = {
'api_db': ApiDbCommands}
class ManageApp(App): 'test.manage' )
super( ManageApp, self).__init__(
description= 'test management',
version= '1.0',
command_ manager= command, iteritems( ):
command. add_command( k, v)
def __init__(self):
command = CommandManager(
)
for k, v in COMMANDS.
def main(): sys.argv[ 1:])
app = ManageApp()
return app.run(
When I call the 'sync' command defined above, I'd expect the '--version' parameter to be handled by that parser. However, it seems the root parser handles this instead:
$ ./manage.py api_db sync --version 11
manage.py 1.0
The '--help' parameter functions similarly:
$ ./manage.py api_db --help
usage: manage.py [--version] [-v | -q] [--log-file LOG_FILE] [-h] [--debug]
test management
optional arguments:
--version show program's version number and exit
...
Have I done something wrong, or is this a bug on cliff's behalf?