I'm trying a very simple python script with only positional arguments, handled by docopt
.
#!/usr/bin/env python
opt_spec = """Test
Usage: docopt_test (import | export <output_file> <output_format>)
docopt_test (-h | --help)
docopt_test (-v | --version)
Options:
-h --help Show this screen.
-v --version Show version.
"""
from docopt import docopt
if __name__ == '__main__':
arguments = docopt(opt_spec, version='Test 1.0')
print(arguments)
When run it will print:
./docopt_test.py export file.xml xml
{'--help': False,
'--version': False,
'<output_file>': 'file.xml',
'<output_format>': 'xml',
'export': True,
'import': False}
The problem is that the output_file
and output_format
arguments retain the <
and >
delimiters in the name, making calls like args['output_file']
impossible. Removing the delimiters from the usage string changes the semantics, making the options into keywords.
Is there a way to solve this without having to resort to usage like args['<output_file>']
?