-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathpartial_parse.py
More file actions
executable file
·23 lines (20 loc) · 1.01 KB
/
Copy pathpartial_parse.py
File metadata and controls
executable file
·23 lines (20 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
from argparse import ArgumentParser
from itertools import chain
if __name__ == '__main__':
arg_parser = ArgumentParser(description='illustration of how to '
'use options that can occur '
'multiple times, and not '
'handling all')
arg_parser.add_argument('-l', action='append', dest='resoure_specs',
help='resources can be specified with '
'multiple -l options')
arg_parser.add_argument('-A', dest='account', help='credit account')
options, unparsed = arg_parser.parse_known_args()
if options.resoure_specs:
specs = chain.from_iterable(map(lambda x: x.split(','),
options.resoure_specs))
print('resources: ' + ', '.join(specs))
if options.account:
print(f'account: {options.account}')
print('unparsed: ' + ', '.join(unparsed))