Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. ```sh
  2. $ cat hoge.py
  3. from docopt import docopt
  4.  
  5. __doc__ = """Can docopt allow the sme name argument differ single/multiple between subcommands?
  6.  
  7. Usage:
  8. hoge.py a <arg>
  9. hoge.py b <arg>...
  10. """
  11.  
  12. args = docopt(__doc__)
  13.  
  14. print('subcommand: %s' % ('a' if args['a'] else 'b' if args['b'] else None))
  15. print('<arg> = %s' % repr(args['<arg>']))
  16. ```
  17.  
  18. ```sh
  19. $ python3 hoge.py a
  20. Usage:
  21. hoge.py a <arg>
  22. hoge.py b <arg>...
  23. $ python3 hoge.py a 1
  24. subcommand: a
  25. <arg> = ['1']
  26. $ python3 hoge.py a 1 2
  27. Usage:
  28. hoge.py a <arg>
  29. hoge.py b <arg>...
  30. $ python3 hoge.py b
  31. Usage:
  32. hoge.py a <arg>
  33. hoge.py b <arg>...
  34. $ python3 hoge.py b 1
  35. subcommand: b
  36. <arg> = ['1']
  37. $ python3 hoge.py b 1 2
  38. subcommand: b
  39. <arg> = ['1', '2']
  40. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement