Skip to content

Commit 85ec58b

Browse files
committed
Added CLI arguments to skip and warn-list lints
1 parent 496af2c commit 85ec58b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

yml2block/__main__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ def main():
9292

9393
@main.command()
9494
@click.argument("file_path")
95+
@click.option("--warn", "-w", multiple=True)
96+
@click.option("--skip", "-s", multiple=True)
9597
@click.option("--verbose", "-v", count=True, help="Print performed checks to stdout.")
96-
def check(file_path, verbose):
98+
def check(file_path, warn, skip, verbose):
9799
"""Lint and validate a (yml or tsv) metadata block file.
98100
99101
Loads the input file and performs a series of checks defined in the rules.py module.
@@ -106,7 +108,7 @@ def check(file_path, verbose):
106108
are also performed.
107109
"""
108110
lint_violations = ViolationsByFile()
109-
lint_conf = LintConfig()
111+
lint_conf = LintConfig.from_cli_args(warn, skip)
110112

111113
if verbose:
112114
print(f"Checking input file: {file_path}\n\n")
@@ -146,6 +148,8 @@ def check(file_path, verbose):
146148
@main.command()
147149
@click.argument("file_path")
148150
@click.option("--verbose", "-v", count=True, help="Print performed checks to stdout.")
151+
@click.option("--warn", "-w", multiple=True)
152+
@click.option("--skip", "-s", multiple=True)
149153
@click.option(
150154
"--outfile", "-o", nargs=1, help="Path to where the output file will be written."
151155
)
@@ -170,7 +174,7 @@ def convert(file_path, verbose, outfile):
170174
print(f"Checking input file: {file_path}\n\n")
171175

172176
lint_violations = ViolationsByFile()
173-
lint_conf = LintConfig()
177+
lint_conf = LintConfig.from_cli_args(warn, skip)
174178

175179
input_type, file_ext_violations = guess_input_type(file_path)
176180
lint_violations.extend_for(file_path, file_ext_violations)

yml2block/rules.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ def __init__(self):
8080
"""Create an empty config."""
8181
self.overrides = dict()
8282

83+
@classmethod
84+
def from_cli_args(cls, warn, skip):
85+
"""Create config ussing warning and skip lists from CLI."""
86+
conf = cls()
87+
for warn_lint in warn:
88+
lint = LINT_NAMES[warn_lint]
89+
conf.warning(lint)
90+
for skip_lint in skip:
91+
lint = LINT_NAMES[skip_lint]
92+
conf.skip(lint)
93+
return conf
94+
8395
def get(self, lint):
8496
"""Return an overridden lint, if present. Otherwise keep original lint."""
8597
try:
@@ -343,3 +355,8 @@ def no_trailing_white_spaces(list_item, tsv_keyword, level=Level.ERROR):
343355
)
344356
)
345357
return violations
358+
359+
360+
LINT_NAMES = {
361+
"ws": no_trailing_white_spaces,
362+
}

0 commit comments

Comments
 (0)