-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutils.py
27 lines (23 loc) · 812 Bytes
/
utils.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
from typing import *
def get_arg(args: List[str], short_name: str, long_name: str) -> Optional[str]:
for i in range(len(args)):
arg = args[i]
if arg[0] != '-':
return None
if arg.startswith('--%s=' % long_name):
args.remove(arg)
return arg.replace('--%s=' % long_name, '')
elif arg == '-%s' % short_name:
result = args[i + 1]
args.remove('-%s' % short_name)
args.remove(result)
return result
return None
def has_arg(args: List[str], short_name: str, long_name: str) -> bool:
for arg in args:
if arg[0] != '-':
return False
if arg == '--%s' % long_name or arg == '-%s' % short_name:
args.remove(arg)
return True
return False