forked from codecov/codecov-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_dump.py
31 lines (23 loc) · 835 Bytes
/
command_dump.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
import subprocess
def command_dump(commands):
print(f"Dumping {' '.join(commands)}")
command_docs = subprocess.run(
[*commands, "--help"], capture_output=True
).stdout.decode("utf-8")
split_docs = command_docs.split("\n")
try:
index_of = split_docs.index("Commands:")
except ValueError:
return command_docs
if "Commands:" in split_docs:
sub_commands = [
sub_command.strip() for sub_command in split_docs[index_of + 1 :] if sub_command.strip()
]
for sub_command in sub_commands:
command_docs = "\n".join(
[command_docs, command_dump([*commands, sub_command])]
)
with open("codecovcli_commands", "w") as f:
f.write(command_docs)
if __name__ == "__main__":
command_dump(["codecovcli"])