-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse_args.py
29 lines (25 loc) · 889 Bytes
/
parse_args.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from sys import argv
# This class is used by tree_sim.py to help parse command line arguments
class ParsedArgs:
def __init__(self):
self.path = argv[0]
self.by_index = []
self.by_flag = dict()
flag = None
for arg in argv[1:]:
if arg[0] == "-":
if flag is not None:
self.by_flag[flag] = None
flag = arg
elif flag is not None:
if flag in self.by_flag:
if type(self.by_flag) == list:
self.by_flag[flag].append(arg)
else:
self.by_flag[flag] = [self.by_flag[flag], arg]
self.by_flag[flag] = arg
flag = None
else:
self.by_index.append(arg)
if flag is not None:
self.by_flag[flag] = None