-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
48 lines (42 loc) · 1.61 KB
/
generate.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
import argparse
import json
file_options = [
"audit_regressor",
"cache_file",
"initial_regressor",
"input_feature_regularizer",
"data",
"output_feature_regularizer_text",
"output_feature_regularizer_binary",
"final_regressor",
]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"input", help="Options file in JSON format produced by vw-dump-options"
)
args = parser.parse_args()
# Options may exist in more than one group, but we only want to produce a
# single description for each.
already_seen_options = set()
with open(args.input, "r") as f:
options_obj = json.load(f)
for group in options_obj["option_groups"]:
for option in group["options"]:
if option["name"] in already_seen_options:
continue
already_seen_options.add(option["name"])
line = f"complete --command vw --long-option {option['name']}"
if option["short_name"] != "":
line += f" --short-option {option['short_name']}"
help_with_newlines_removed = "".join(option["help"].splitlines()).replace("'", r"\'")
line += (
f" --description '{option['name']}: {help_with_newlines_removed}'"
)
if option["name"] in file_options:
line += " --force-files"
else:
line += " --no-files"
if option["type"] != "bool":
line += " --require-parameter"
print(line)