Skip to content

Commit 557728f

Browse files
committed
Streamline CLI help
Also add CLI to console scripts Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 9a559bf commit 557728f

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ dev =
109109
[options.entry_points]
110110
console_scripts =
111111
vulnerablecode = vulnerablecode:command_line
112-
112+
vulntotal = vulntotal.vulntotal_cli:handler

vulntotal/vulntotal_cli.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,33 @@
2525

2626

2727
@click.command()
28+
@click.argument("purl", required=False)
29+
@click.option(
30+
"--json",
31+
"json_output",
32+
type=click.File("w"),
33+
required=False,
34+
metavar="FILE",
35+
help="Write output as pretty-printed JSON to FILE. Use '-' to print on screen.",
36+
)
37+
@click.option(
38+
"--yaml",
39+
"yaml_output",
40+
type=click.File("w"),
41+
required=False,
42+
metavar="FILE",
43+
help="Write output as YAML to FILE. Use '-' to print on screen.",
44+
)
45+
46+
# hidden debug options
2847
@click.option(
2948
"-l",
3049
"--list",
3150
"list_source",
3251
is_flag=True,
3352
multiple=False,
3453
required=False,
35-
help="Lists all the available DataSources.",
54+
help="List available datasources.",
3655
)
3756
@click.option(
3857
"-e",
@@ -42,7 +61,7 @@
4261
multiple=True,
4362
type=click.Choice(DATASOURCE_REGISTRY.keys()),
4463
required=False,
45-
help="Enable these datasource/s only.",
64+
help="Enable only this datasource. Repeat for multiple datasources. Used for debugging.",
4665
)
4766
@click.option(
4867
"-d",
@@ -52,15 +71,15 @@
5271
multiple=True,
5372
type=click.Choice(DATASOURCE_REGISTRY.keys()),
5473
required=False,
55-
help="Disable these datasource/s.",
74+
help="Disable this datasource. Repeat for multiple datasources. Used for debugging.",
5675
)
5776
@click.option(
5877
"--ecosystem",
5978
"ecosystem",
6079
hidden=True,
6180
is_flag=True,
6281
required=False,
63-
help="Lists ecosystem supported by active DataSources",
82+
help="List package ecosystem supported by active datasources. Used for debugging.",
6483
)
6584
@click.option(
6685
"--raw",
@@ -69,7 +88,7 @@
6988
hidden=True,
7089
multiple=False,
7190
required=False,
72-
help="List of all the raw response from DataSources.",
91+
help="Report the raw responses from each datasource. Used for debugging. Used for debugging.",
7392
)
7493
@click.option(
7594
"--no-threading",
@@ -78,7 +97,7 @@
7897
hidden=True,
7998
multiple=False,
8099
required=False,
81-
help="Run DataSources sequentially.",
100+
help="Query datasources sequentially. Used for debugging.",
82101
)
83102
@click.option(
84103
"-p",
@@ -88,23 +107,7 @@
88107
hidden=True,
89108
multiple=False,
90109
required=False,
91-
help="Enable default pagination.",
92-
)
93-
@click.option(
94-
"--json",
95-
"json_output",
96-
type=click.File("w"),
97-
required=False,
98-
metavar="FILE",
99-
help="Write output as pretty-printed JSON to FILE. ",
100-
)
101-
@click.option(
102-
"--yaml",
103-
"yaml_output",
104-
type=click.File("w"),
105-
required=False,
106-
metavar="FILE",
107-
help="Write output as YAML to FILE. ",
110+
help="Enable default pagination. Used for debugging.",
108111
)
109112
@click.option(
110113
"--no-group",
@@ -113,9 +116,8 @@
113116
hidden=True,
114117
multiple=False,
115118
required=False,
116-
help="Don't group by CVE.",
119+
help="Do not group output by vulnerability/CVE. Used for debugging.",
117120
)
118-
@click.argument("purl", required=False)
119121
@click.help_option("-h", "--help")
120122
def handler(
121123
purl,
@@ -131,8 +133,7 @@ def handler(
131133
no_group,
132134
):
133135
"""
134-
Runs the PURL through all the available datasources and group vulnerability by CVEs.
135-
Use the special '-' file name to print JSON or YAML results on screen/stdout.
136+
Search all the available vulnerabilities databases for the package-url PURL.
136137
"""
137138
active_datasource = (
138139
get_enabled_datasource(enable)
@@ -144,7 +145,7 @@ def handler(
144145
list_datasources()
145146

146147
elif not active_datasource:
147-
click.echo("No datasources available!", err=True)
148+
click.echo("No datasource available!", err=True)
148149

149150
elif ecosystem:
150151
list_supported_ecosystem(active_datasource)
@@ -176,7 +177,7 @@ def get_valid_datasources(datasources):
176177
except KeyError:
177178
unknown_datasources.append(key)
178179
if unknown_datasources:
179-
raise CommandError(f"Unknown datasource: {unknown_datasources}")
180+
raise Exception(f"Unknown datasources: {unknown_datasources}")
180181
return valid_datasources
181182

182183

@@ -197,13 +198,13 @@ def list_datasources():
197198

198199
def list_supported_ecosystem(datasources):
199200
ecosystems = []
200-
for key, datasource in datasources.items():
201+
for _key, datasource in datasources.items():
201202
vendor_supported_ecosystem = datasource.supported_ecosystem()
202203
ecosystems.extend([x.upper() for x in vendor_supported_ecosystem.keys()])
203204

204205
active_datasource = [x.upper() for x in datasources.keys()]
205-
click.echo("Active DataSources: %s\n" % ", ".join(sorted(active_datasource)))
206-
click.echo("Ecosystem supported by active datasources")
206+
click.echo("Active datasources: %s\n" % ", ".join(sorted(active_datasource)))
207+
click.echo("Package ecosystem supported by active datasources")
207208
click.echo("\n".join(sorted(set(ecosystems))))
208209

209210

@@ -281,8 +282,8 @@ def prettyprint(purl, datasources, pagination, no_threading):
281282
if not vulnerabilities:
282283
return
283284

284-
active_datasource = ", ".join(sorted([x.upper() for x in datasources.keys()]))
285-
metadata = f"PURL: {purl}\nActive DataSources: {active_datasource}\n\n"
285+
active_datasources = ", ".join(sorted([x.upper() for x in datasources.keys()]))
286+
metadata = f"PURL: {purl}\nActive datasources: {active_datasources}\n\n"
286287

287288
table = Texttable()
288289
table.set_cols_dtype(["t", "t", "t", "t"])

0 commit comments

Comments
 (0)