Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- if __name__ == '__main__':
- desc = '''
- An example of how to use argparse
- ./CMD SUBCOMMAND [options...]
- SUB COMMANDS:
- record
- report
- ...
- '''
- arg_parser = argparse.ArgumentParser(description=desc)
- sub_parser = arg_parser.add_subparsers(dest='sub_cmd')
- sub_init = sub_parser.add_parser('record',
- help='Record')
- sub_init.add_argument('-i', '--ip',
- action='store',
- required=True,
- help='hostname for target')
- sub_init.add_argument('--user',
- action='store',
- metavar='USER',
- default='root',
- help='User name for a target')
- sub_init.add_argument('--port',
- action='store',
- type=int,
- default=22,
- help='Port for a target')
- sub_init.add_argument('--append',
- action='store_true',
- help='Append traced data')
- sub_report = sub_parser.add_parser('report',
- help='Report helper')
- sub_report.add_argument('--filter-pid', action='store',
- nargs='*',
- type=int,
- metavar='PID',
- help='Filter PIDs')
- args = arg_parser.parse_args()
- # If subcommand doesn't exist?
- if not args.sub_cmd:
- arg_parser.print_help()
- exit(0)
- if args.sub == 'record':
- # Do something
- pass
- elif args.sub == 'report':
- # Do something
- pass
Add Comment
Please, Sign In to add comment