Skip to content

Commit 6671b20

Browse files
committed
organize command line options into groups
1 parent 7f4b881 commit 6671b20

File tree

2 files changed

+88
-80
lines changed

2 files changed

+88
-80
lines changed

schema_salad/main.py

Lines changed: 85 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Command line interface to schema-salad."""
22

33
import argparse
4+
import importlib.metadata
45
import logging
56
import os
67
import sys
@@ -24,7 +25,6 @@
2425
if int(rdflib_version.split(".", maxsplit=1)[0]) < 6:
2526
register("json-ld", Parser, "rdflib_jsonld.parser", "JsonLDParser")
2627

27-
import importlib.metadata
2828

2929
_logger: Final = logging.getLogger("salad")
3030

@@ -42,195 +42,203 @@ def printrdf(
4242
def arg_parser() -> argparse.ArgumentParser:
4343
"""Build the argument parser."""
4444
RichHelpFormatter.group_name_formatter = str
45-
parser: Final = argparse.ArgumentParser(formatter_class=RichHelpFormatter)
45+
parser: Final = argparse.ArgumentParser(
46+
formatter_class=RichHelpFormatter, description="Validate Salad schemas or documents."
47+
)
4648
parser.add_argument(
4749
"--rdf-serializer",
48-
help="Output RDF serialization format used by --print-rdf"
49-
"(one of turtle (default), n3, nt, xml)",
50+
help="Output RDF serialization format used by --print-rdf "
51+
"(one of `turtle` (default), `n3`, `nt`, `xml`)",
5052
default="turtle",
5153
)
52-
5354
parser.add_argument(
5455
"--skip-schemas",
5556
action="store_true",
5657
default=False,
57-
help="If specified, ignore $schemas sections.",
58+
help="If specified, ignore `$schemas` sections.",
5859
)
5960
parser.add_argument(
6061
"--strict-foreign-properties",
6162
action="store_true",
6263
help="Strict checking of foreign properties",
6364
default=False,
6465
)
66+
parser.add_argument("schema", type=str, nargs="?", default=None)
67+
parser.add_argument("document", type=str, nargs="*", default=None)
68+
parser.add_argument("--version", "-v", action="store_true", help="Print version", default=None)
69+
70+
parser.add_argument(
71+
"--generate-help-preview",
72+
action=HelpPreviewAction,
73+
path="help-preview.svg", # (optional) or "help-preview.html" or "help-preview.txt"
74+
)
6575

66-
exgroup: Final = parser.add_mutually_exclusive_group()
67-
exgroup.add_argument(
76+
exgroup: Final = parser.add_argument_group(title="Output type and format")
77+
output_exclusive = exgroup.add_mutually_exclusive_group()
78+
output_exclusive.add_argument(
6879
"--print-jsonld-context",
6980
action="store_true",
7081
help="Print JSON-LD context for schema",
7182
)
72-
exgroup.add_argument("--print-rdfs", action="store_true", help="Print RDF schema")
73-
exgroup.add_argument("--print-avro", action="store_true", help="Print Avro schema")
74-
75-
exgroup.add_argument(
83+
output_exclusive.add_argument("--print-rdfs", action="store_true", help="Print RDF schema")
84+
output_exclusive.add_argument("--print-avro", action="store_true", help="Print Avro schema")
85+
output_exclusive.add_argument(
7686
"--print-rdf",
7787
action="store_true",
7888
help="Print corresponding RDF graph for document",
7989
)
80-
exgroup.add_argument(
90+
output_exclusive.add_argument(
8191
"--print-pre", action="store_true", help="Print document after preprocessing"
8292
)
83-
exgroup.add_argument("--print-index", action="store_true", help="Print node index")
84-
exgroup.add_argument("--print-metadata", action="store_true", help="Print document metadata")
85-
exgroup.add_argument(
93+
output_exclusive.add_argument("--print-index", action="store_true", help="Print node index")
94+
output_exclusive.add_argument(
95+
"--print-metadata", action="store_true", help="Print document metadata"
96+
)
97+
output_exclusive.add_argument(
8698
"--print-inheritance-dot",
8799
action="store_true",
88100
help="Print graphviz file of inheritance",
89101
)
90-
exgroup.add_argument(
102+
output_exclusive.add_argument(
91103
"--print-fieldrefs-dot",
92104
action="store_true",
93105
help="Print graphviz file of field refs",
94106
)
95-
96-
exgroup.add_argument(
107+
output_exclusive.add_argument(
97108
"--codegen",
98109
type=str,
99-
metavar="language",
110+
metavar="LANGUAGE",
100111
help="Generate classes in target language, currently supported: "
101-
"python, java, typescript, dotnet, cpp, dlang",
112+
"`python`, `java`, `typescript`, `dotnet`, `cpp`, `dlang`",
113+
)
114+
output_exclusive.add_argument(
115+
"--print-oneline",
116+
action="store_true",
117+
help="Print each error message in oneline",
118+
)
119+
output_exclusive.add_argument(
120+
"--print-doc", action="store_true", help="Print HTML schema documentation page"
102121
)
103122

104-
parser.add_argument(
123+
codegen_opts = parser.add_argument_group(
124+
title="Code generation configuration", description="Requires --codegen LANGUAGE"
125+
)
126+
codegen_opts.add_argument(
105127
"--codegen-target",
106128
type=str,
107129
default=None,
108-
help="Defaults to sys.stdout for Python/C++/Dlang and ./ for " "Java/TypeScript/.Net",
130+
help="Defaults to `sys.stdout` for Python/C++/Dlang and `./` for Java/TypeScript/.Net",
109131
)
110132

111-
parser.add_argument(
133+
codegen_opts.add_argument(
112134
"--codegen-examples",
113135
type=str,
114-
metavar="directory",
136+
metavar="DIRECTORY",
115137
default=None,
116138
help="Directory of example documents for test case generation (Java/TypeScript/.Net/Dlang only).",
117139
)
118140

119-
parser.add_argument(
141+
codegen_opts.add_argument(
120142
"--codegen-package",
121143
type=str,
122-
metavar="dotted.package",
144+
metavar="DOTTED.PACKAGE",
123145
default=None,
124-
help="Optional override of the package name which is other derived "
146+
help="Optional override of the package name which is otherwise derived "
125147
"from the base URL (Java/TypeScript/.Net/Dlang only).",
126148
)
127149

128-
parser.add_argument(
150+
codegen_opts.add_argument(
129151
"--codegen-copyright",
130152
type=str,
131-
metavar="copyright_string",
153+
metavar="COPYRIGHT_STRING",
132154
default=None,
133155
help="Optional copyright of the input schema.",
134156
)
135157

136-
parser.add_argument(
158+
codegen_opts.add_argument(
137159
"--codegen-spdx-copyright-text",
138160
nargs="+",
139-
metavar="spdx_copyright_text",
161+
metavar="SPDX_COPYRIGHT_TEXT",
140162
default=[],
141163
help="List of copyright text. Each entry will show up as "
142-
"'SPDX-FileCopyrightText: ...' (Currently c++ only)",
164+
"`SPDX-FileCopyrightText: ...` (Currently C++ only)",
143165
)
144166

145-
parser.add_argument(
167+
codegen_opts.add_argument(
146168
"--codegen-spdx-license-identifier",
147169
type=str,
148-
metavar="spdx_license_identifier",
170+
metavar="SPDX_LICENSE_IDENTIFIER",
149171
default=None,
150-
help="Optional spdx license identifier, e.g.: GPL-3.0-only (Currently c++ only)",
172+
help="Optional spdx license identifier, e.g.: GPL-3.0-only (Currently C++ only)",
151173
)
152174

153-
parser.add_argument(
175+
codegen_opts.add_argument(
154176
"--codegen-parser-info",
155-
metavar="parser_info",
177+
metavar="PARSER_INFO",
156178
type=str,
157179
default=None,
158180
help="Optional parser name which is accessible via resulted parser API (Python and Dlang only)",
159181
)
160182

161-
exgroup.add_argument(
162-
"--print-oneline",
163-
action="store_true",
164-
help="Print each error message in oneline",
165-
)
166-
167-
exgroup.add_argument(
168-
"--print-doc", action="store_true", help="Print HTML schema documentation page"
169-
)
170-
171-
exgroup_strict: Final = parser.add_mutually_exclusive_group()
172-
exgroup_strict.add_argument(
183+
exgroup_strict: Final = parser.add_argument_group(title="Validation strictness")
184+
strict_exclusive = exgroup_strict.add_mutually_exclusive_group()
185+
strict_exclusive.add_argument(
173186
"--strict",
174187
action="store_true",
175188
help="Strict validation (unrecognized or out of place fields are error)",
176189
default=True,
177190
dest="strict",
178191
)
179-
exgroup_strict.add_argument(
192+
strict_exclusive.add_argument(
180193
"--non-strict",
181194
action="store_false",
182195
help="Lenient validation (ignore unrecognized fields)",
183196
default=True,
184197
dest="strict",
185198
)
186199

187-
exgroup_volume: Final = parser.add_mutually_exclusive_group()
188-
exgroup_volume.add_argument("--verbose", action="store_true", help="Default logging")
189-
exgroup_volume.add_argument(
200+
exgroup_volume: Final = parser.add_argument_group(title="Logging detail level")
201+
logging_exclusive = exgroup_volume.add_mutually_exclusive_group()
202+
logging_exclusive.add_argument("--verbose", action="store_true", help="Default logging")
203+
logging_exclusive.add_argument(
190204
"--quiet", action="store_true", help="Only print warnings and errors."
191205
)
192-
exgroup_volume.add_argument("--debug", action="store_true", help="Print even more logging")
206+
logging_exclusive.add_argument("--debug", action="store_true", help="Print even more logging")
193207

194-
parser.add_argument(
208+
print_opts = parser.add_argument_group(
209+
title="Documentation generation options", description="Requires --print-doc"
210+
)
211+
print_opts.add_argument(
195212
"--only",
196213
action="append",
197-
help="Use with --print-doc, document only listed types",
214+
help="Document only listed types",
198215
)
199-
parser.add_argument(
216+
print_opts.add_argument(
200217
"--redirect",
201218
action="append",
202-
help="Use with --print-doc, override default link for type",
219+
help="Override default link for type",
203220
)
204-
parser.add_argument("--brand", help="Use with --print-doc, set the 'brand' text in nav bar")
205-
parser.add_argument(
221+
print_opts.add_argument("--brand", help="Set the 'brand' text in nav bar")
222+
print_opts.add_argument(
206223
"--brandlink",
207-
help="Use with --print-doc, set the link for 'brand' in nav bar",
224+
help="Set the link for 'brand' in nav bar",
208225
)
209-
parser.add_argument(
226+
print_opts.add_argument(
210227
"--brandstyle",
211-
help="Use with --print-doc, HTML code to link to an external style sheet",
228+
help="HTML code to link to an external style sheet",
212229
)
213-
parser.add_argument(
230+
print_opts.add_argument(
214231
"--brandinverse",
215232
default=False,
216233
action="store_true",
217-
help="Use with --print-doc",
234+
help="Set to use the dark navigation bar style.",
218235
)
219-
parser.add_argument(
236+
print_opts.add_argument(
220237
"--primtype",
221238
default="#PrimitiveType",
222-
help="Use with --print-doc, link to use for primitive types (string, int etc)",
239+
help="Link to use for primitive types (string, int etc)",
223240
)
224241

225-
parser.add_argument("schema", type=str, nargs="?", default=None)
226-
parser.add_argument("document", type=str, nargs="*", default=None)
227-
parser.add_argument("--version", "-v", action="store_true", help="Print version", default=None)
228-
229-
parser.add_argument(
230-
"--generate-help-preview",
231-
action=HelpPreviewAction,
232-
path="help-preview.svg", # (optional) or "help-preview.html" or "help-preview.txt"
233-
)
234242
return parser
235243

236244

schema_salad/makedoc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,14 @@ def avrold_doc(
689689
"""
690690
)
691691

692-
navbar_extraclass: Final = "navbar-inverse" if brandinverse else ""
692+
navbarclass: Final = "navbar-dark bg-dark " if brandinverse else "navbar-light bg-light "
693693
outdoc.write(
694694
"""
695-
<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-light {}">
695+
<nav class="navbar sticky-top navbar-expand-lg {}">
696696
<div class="container">
697697
<a class="navbar-brand" href="{}">{}</a>
698698
""".format(
699-
navbar_extraclass, brandlink, brand
699+
navbarclass, brandlink, brand
700700
)
701701
)
702702

0 commit comments

Comments
 (0)