I'm trying to learn pythons docopt module and have the following simple script:
""" Usage: rsnapshot-once [-c CFGFILE] (sync|hourly|daily|monthly) -c CFGFILE specify the configfile that rsnapshot should use """ import logging import sys from docopt import docopt args = docopt(__doc__, version='0.0.1-alpha') logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, formatter=logging.BASIC_FORMAT) logging.debug("Parsed arguments:\n" + str(args)); if not args.get("-c"): args['CFGFILE'] = "/etc/rsnapshot.conf" When invoked from the command line with the -c option:
% ./rsnapshot-once.py -c someconfigfile sync DEBUG:root:Parsed arguments: {'-c': True, 'CFGFILE': 'someconfigfile', 'daily': False, 'hourly': False, 'monthly': False, 'sync': True} When only the command is passed:
% ./rsnapshot-once.py daily Usage: rsnapshot-once [-c CFGFILE] (sync|hourly|daily|monthly) It seems, that I am misunderstanding something. Could anyone give me a hint, what I'm doing wrong?
Thanks