[root@shuffle-dev py_test]$ vim doc.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Naval Fate.
Usage:
doc.py ship new <name>...
doc.py ship <name> move <x> <y> [--speed=<kn>]
doc.py ship shoot <x> <y>
doc.py mine (set|remove) <x> <y> [--moored | --drifting]
doc.py (-h | --help)
doc.py --version
doc.py [--name NAME] [-h] [--version]
Options:
--name NAME Your name
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
"""
from docopt import docopt
if __name__ == '__main__':
arguments = docopt(__doc__, version='Naval Fate 2.0')
print(arguments)
[root@shuffle-dev py_test]$ python doc.py --name shuffle
{'--drifting': False,
'--help': False,
'--moored': False,
'--name': 'shuffle',
'--speed': '10',
'--version': False,
'<name>': [],
'<x>': None,
'<y>': None,
'mine': False,
'move': False,
'new': False,
'remove': False,
'set': False,
'ship': False,
'shoot': False}
[root@shuffle-dev py_test]$ python doc.py ship new shuffle
{'--drifting': False,
'--help': False,
'--moored': False,
'--name': None,
'--speed': '10',
'--version': False,
'<name>': ['shuffle'],
'<x>': None,
'<y>': None,
'mine': False,
'move': False,
'new': True,
'remove': False,
'set': False,
'ship': True,
'shoot': False}
网友评论