Skip to content

Commit dd07d88

Browse files
committed
fix #147
1 parent f6e42d2 commit dd07d88

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

licensecheck/io/cli.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def cli() -> None: # pragma: no cover
3232
parser.add_argument(
3333
"--format",
3434
"-f",
35-
help=f"Output format. one of: {', '.join(set(fmt.formatMap))}. default=simple",
35+
help=f"Output format. one of: {', '.join(x.value for x in fmt.FMT)}. default=simple",
3636
)
3737
parser.add_argument(
3838
"--requirements-paths",
@@ -84,7 +84,7 @@ def cli() -> None: # pragma: no cover
8484
)
8585
parser.add_argument(
8686
"--skip-dependencies",
87-
help="set of packages/dependencies to skip (this sets the 'compatability' to True)",
87+
help="set of packages/dependencies to skip (this sets the 'compatibility' to True)",
8888
nargs="+",
8989
)
9090
parser.add_argument(
@@ -109,6 +109,9 @@ def cli() -> None: # pragma: no cover
109109
)
110110
args = vars(parser.parse_args())
111111

112+
if args.get("format", "simple") not in fmt.FMT:
113+
args["format"] = "simple"
114+
112115
stdin_path = Path("__stdin__")
113116
if not args.get("requirements_paths"):
114117
if stdin.isatty():
@@ -182,11 +185,10 @@ def main(licensecheckConf: LC_Config) -> int:
182185
)
183186
raise ValueError(msg)
184187

185-
format_ = licensecheckConf.format or "simple"
186-
if licensecheckConf.format in fmt.formatMap:
188+
if licensecheckConf.format in fmt.FMT:
187189
print(
188190
fmt.fmt(
189-
format_,
191+
licensecheckConf.format,
190192
this_license,
191193
sorted(depsWithLicenses),
192194
hide_output_parameters,

licensecheck/io/fmt.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from __future__ import annotations
4141

4242
import csv
43+
from enum import StrEnum, auto
4344
import json
4445
import re
4546
from collections import OrderedDict
@@ -326,11 +327,19 @@ def fmt(
326327
return formatMap.get(format_, plainText)(myLice, pkgs)
327328

328329

330+
class FMT(StrEnum):
331+
json = auto()
332+
markdown = auto()
333+
html = auto()
334+
csv = auto()
335+
ansi = auto()
336+
simple = auto()
337+
329338
formatMap = {
330-
"json": raw,
331-
"markdown": markdown,
332-
"html": html,
333-
"csv": rawCsv,
334-
"ansi": ansi,
335-
"simple": plainText,
339+
FMT.json: raw,
340+
FMT.markdown: markdown,
341+
FMT.html: html,
342+
FMT.csv: rawCsv,
343+
FMT.ansi: ansi,
344+
FMT.simple: plainText,
336345
}

licensecheck/models/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from dataclasses import field
44

55
from licensecheck.models.defaultonnone import DefaultOnNoneModel
6-
6+
from licensecheck.io.fmt import FMT
77

88
class LC_Config(DefaultOnNoneModel):
99
"""LC_Config type."""
1010

1111
file: str = ""
1212
license: str = ""
13-
format: str = ""
13+
format: FMT = FMT.simple
1414
pypi_api: str = ""
1515
show_only_failing: bool = False
1616
zero: bool = False

0 commit comments

Comments
 (0)