forked from gofed/gofed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseOptions.py
53 lines (40 loc) · 1.01 KB
/
parseOptions.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from modules.Utils import runCommand
import re
import sys
def parseOptions(command, plugin_path):
so, se, rc = runCommand("./gofed -p %s %s --help" % (plugin_path, command))
if rc != 0:
return []
options = []
option_f = False
for line in so.split("\n"):
if line == "Options:":
option_f = True
continue
if option_f == True:
if line == "":
break
# line must start with two spaces and minus
if len(line) < 3:
continue
if line[:3] != " -":
continue
line = line.strip()
parts = line.split(' ')[0].split(',')
if parts == []:
continue
# do we have both short and long options?
opts = map(lambda i: i.strip().split(' ')[0].split('=')[0], parts)
for opt in opts:
options.append(opt)
return sorted(options)
if __name__ == "__main__":
if len(sys.argv) != 3:
print ""
command = sys.argv[1]
plugin_path = sys.argv[2]
options = parseOptions(command, plugin_path)
if options == []:
print command + ":"
else:
print command + ":" + " ".join(options)