forked from sinojelly/mockcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_long_opt.py
More file actions
40 lines (29 loc) · 906 Bytes
/
get_long_opt.py
File metadata and controls
40 lines (29 loc) · 906 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
import getopt, sys
class LongOptString:
def __init__(self, optString, example):
self.optString = optString
self.example = example
def toAssignable(self):
return self.optString + '='
def toLongOptString(self):
return '--' + self.optString
def toLongAssignable(self):
return '--' + self.optString + '='
def toUsage(self):
return self.toLongAssignable() + self.example
def getAssignableOptStrings(longOpts):
return [i.toAssignable() for i in longOpts]
def getUsageString(longOpts):
return " ".join([i.toUsage() for i in longOpts])
def usage(longOpts):
print(sys.argv[0], getUsageString(longOpts))
def getOpt(longOpts):
try:
return getopt.getopt(sys.argv[1:], '', getAssignableOptStrings(longOpts))
except (getopt.GetoptError, err):
print(str(err), file=sys.stderr)
usage(longOpts)
sys.exit(2)
def getContent(lines):
return "\n".join(lines) + "\n"