Guest User

Untitled

a guest
Jul 16th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import argparse
  2.  
  3. parser = argparse.ArgumentParser()
  4.  
  5. subparsers = parser.add_subparsers(help='commands')
  6.  
  7. # A list command
  8. list_parser = subparsers.add_parser('list', help='List contents')
  9. list_parser.add_argument('dirname', action='store', help='Directory to list')
  10.  
  11. # A create command
  12. create_parser = subparsers.add_parser('create', help='Create a directory')
  13. create_parser.add_argument('dirname', action='store', help='New directory to create')
  14. create_parser.add_argument('--read-only', default=False, action='store_true',
  15.                            help='Set permissions to prevent writing to the directory',
  16.                            )
  17.  
  18. # A delete command
  19. delete_parser = subparsers.add_parser('delete', help='Remove a directory')
  20. delete_parser.add_argument('dirname', action='store', help='The directory to remove')
  21. delete_parser.add_argument('--recursive', '-r', default=False, action='store_true',
  22.                            help='Remove the contents of the directory, too',
  23.                            )
  24.  
  25. print parser.parse_args()
Add Comment
Please, Sign In to add comment