-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs.py
59 lines (46 loc) · 1.67 KB
/
docs.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
54
55
56
57
58
59
import subprocess
import re
def extract_items_from_brackets(input):
"""Extracts items within the first line of brackets from output.
Args:
output: The output string.
Returns:
A list of items within the first line of brackets.
"""
match = re.search(r"\{(.*?)\}", input, re.MULTILINE)
if match:
items = match.group(1).split(",")
return items
else:
return []
# Example usage
# output = "This is some output {item1, item2, item3}"
# result = extract_items_from_brackets(output)
# print(result) # Output: ['item1', 'item2', 'item3']
def call_help_for_arguments(script_path):
"""
Calls `--help` for each argument listed in the script's help message.
Args:
script_path: The path to the script.
"""
# Get the help message
help_output = subprocess.check_output(['python', script_path, '--help'], text=True)
# Extract the arguments
arguments = extract_items_from_brackets(help_output.splitlines()[0])
print("========================================")
print(f"Available commands: {arguments}")
# for line in help_output.splitlines():
# if line.startswith(' -'):
# argument = line.split()[1]
# arguments.append(argument)
# Call `--help` for each argument
for argument in arguments:
print("========================================")
print(f"Calling --help for argument: {argument}")
print("========================================")
output = subprocess.check_output(['python', script_path, argument, '--help'], text=True)
print(output)
print("\n")
# Replace 'myscript/__init__.py' with the actual path to your script
script_path = 'sleeper_data_pypline/__init__.py'
call_help_for_arguments(script_path)