Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathchecker.py
More file actions
Latest commit
98 lines (81 loc) · 3.28 KB
/
Copy pathchecker.py
File metadata and controls
98 lines (81 loc) · 3.28 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
fromSoftLayer.CLIimportenvironment
fromclick.testingimportCliRunner
fromSoftLayer.CLI.coreimportcli
importitertools
runner=CliRunner()
env=environment.Environment()
env.load()
TopLevelCommands=env.list_commands()
deffindHelp(Table):
forrowinTable:
if'--help'inrow:
returnTrue
returnFalse
deffindCorrectFlagTable(arrayCommandByLine):
cont=0
arrayTable= []
forlineinarrayCommandByLine:
if'─'inline:
cont+=1
ifcont==2:
ifnotfindHelp(arrayTable):
arrayTable= []
cont=0
if'│'inline:
arrayTable.append(line)
returnarrayTable
defgetFlags(arrayCommandByLine):
flags= []
arrayFlagsTable=findCorrectFlagTable(arrayCommandByLine)
forlineinarrayFlagsTable:
arrayFlags=line.split('│')
ifarrayFlags[1].strip() !='':
flags.append(f'{arrayFlags[1].strip()},{arrayFlags[2].strip()}: {arrayFlags[3].strip()}')
else:
flags.append(f'{arrayFlags[2].strip()}: {arrayFlags[3].strip()}')
returnflags
deffindCommandNested(arrayCommandByLine):
commandNested=False
commands= []
forlineinarrayCommandByLine:
ifcommandNested:
nestedCommand=line.split(' ')
commands.append(nestedCommand[2])
if'Commands:'inline:
commandNested=True
returncommands
defprintCommandName(TopLevelCommand, command, nestedCommandName=''):
ifnestedCommandName!='':
f.write(f'slcli {TopLevelCommand}{command}{nestedCommandName}\n')
else:
f.write(f'slcli {TopLevelCommand}{command}\n')
defprintBody(commandArray):
forflagingetFlags(commandArray):
f.write(f'\tFlag: {flag}\n')
f.write("\t--------------------------------\n")
f.write(f'\tDescription: {commandArray[2].strip()}\n')
f.write("\t--------------------------------\n")
list_of_strings="".join(commandArray[0])
command_strings=list_of_strings.replace("Usage: cli","Usage: slcli")
grouped_strings= ["".join(g) fork, ginitertools.groupby(command_strings, lambdax: x==" ") ifnotk]
f.write(f'\t{" ".join(grouped_strings)}\n')
f.write("==============================================================\n")
# Main Function
withopen('output.txt', "w", encoding="utf-8") asf:
f.write('SLCLI Command Directory\n')
f.write("==============================================================\n")
forTopLevelCommandinTopLevelCommands:
commands=env.list_commands(TopLevelCommand)
forcommandincommands:
result=runner.invoke(cli, [TopLevelCommand, command, '--help'])
commandArray=result.output.splitlines()
nestedCommands=findCommandNested(commandArray)
iflen(nestedCommands) !=0:
fornestedCommandinnestedCommands:
result=runner.invoke(cli, [TopLevelCommand, command, nestedCommand, '--help'])
commandArray=result.output.splitlines()
printCommandName(TopLevelCommand, command, nestedCommand)
printBody(commandArray)
else:
printCommandName(TopLevelCommand, command)
printBody(commandArray)