Skip to content

Commit 912ef34

Browse files
committed
Added script to list all commands in slcli
1 parent d589ba4 commit 912ef34

File tree

3 files changed

+3360
-0
lines changed

3 files changed

+3360
-0
lines changed

cliChecker/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## SLCLI Checker
2+
3+
Script to list all commands in order to compare the changes
4+
5+
From the softlayer-python root directory, do the following after making changes.
6+
7+
```
8+
cd cliChecker
9+
py checker.py
10+
```

cliChecker/checker.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from SoftLayer.CLI import environment
2+
from click.testing import CliRunner
3+
from SoftLayer.CLI.core import cli
4+
5+
runner = CliRunner()
6+
env = environment.Environment()
7+
env.load()
8+
TopLevelCommands = env.list_commands()
9+
10+
11+
def findHelp(Table):
12+
for row in Table:
13+
if '--help' in row:
14+
return True
15+
return False
16+
17+
18+
def findCorrectFlagTable(arrayCommandByLine):
19+
cont = 0
20+
arrayTable = []
21+
for line in arrayCommandByLine:
22+
if '─' in line:
23+
cont += 1
24+
if cont == 2:
25+
if not findHelp(arrayTable):
26+
arrayTable = []
27+
cont = 0
28+
if '│' in line:
29+
arrayTable.append(line)
30+
return arrayTable
31+
32+
33+
def getFlags(arrayCommandByLine):
34+
flags = []
35+
arrayFlagsTable = findCorrectFlagTable(arrayCommandByLine)
36+
37+
for line in arrayFlagsTable:
38+
arrayFlags = line.split('│')
39+
if arrayFlags[1].strip() != '':
40+
flags.append('{},{}: {}'.format(arrayFlags[1].strip(), arrayFlags[2].strip(), arrayFlags[3].strip()))
41+
else:
42+
flags.append('{}: {}'.format(arrayFlags[2].strip(), arrayFlags[3].strip()))
43+
return flags
44+
45+
46+
def findCommandNested(arrayCommandByLine):
47+
commandNested = False
48+
commands = []
49+
for line in arrayCommandByLine:
50+
if commandNested:
51+
nestedCommand = line.split(' ')
52+
commands.append(nestedCommand[2])
53+
if 'Commands:' in line:
54+
commandNested = True
55+
return commands
56+
57+
58+
def printCommandName(TopLevelCommand, command, nestedCommandName=''):
59+
if nestedCommandName != '':
60+
f.write('slcli {} {} {}\n'.format(TopLevelCommand, command, nestedCommandName))
61+
else:
62+
f.write('slcli {} {}\n'.format(TopLevelCommand, command))
63+
64+
65+
def printBody(commandArray):
66+
for flag in getFlags(commandArray):
67+
f.write('\tFlag: {}\n'.format(flag))
68+
f.write("\t--------------------------------\n")
69+
f.write('\tDescription: {}\n'.format(commandArray[2].strip()))
70+
f.write("\t--------------------------------\n")
71+
f.write('\tUsage: {}\n'.format(commandArray[0]))
72+
f.write("==============================================================\n")
73+
74+
75+
# Main Function
76+
with open('output.txt', "w", encoding="utf-8") as f:
77+
f.write('SLCLI Command Directory\n')
78+
f.write("==============================================================\n")
79+
80+
for TopLevelCommand in TopLevelCommands:
81+
commands = env.list_commands(TopLevelCommand)
82+
for command in commands:
83+
result = runner.invoke(cli, [TopLevelCommand, command, '--help'])
84+
commandArray = result.output.splitlines()
85+
nestedCommands = findCommandNested(commandArray)
86+
if len(nestedCommands) != 0:
87+
for nestedCommand in nestedCommands:
88+
result = runner.invoke(cli, [TopLevelCommand, command, nestedCommand, '--help'])
89+
commandArray = result.output.splitlines()
90+
printCommandName(TopLevelCommand, command, nestedCommand)
91+
printBody(commandArray)
92+
else:
93+
printCommandName(TopLevelCommand, command)
94+
printBody(commandArray)

0 commit comments

Comments
 (0)