Skip to content

Commit

Permalink
Added CLI arguments to skip and warn-list lints
Browse files Browse the repository at this point in the history
  • Loading branch information
HenningTimm committed Dec 19, 2023
1 parent 496af2c commit 85ec58b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 7 additions & 3 deletions yml2block/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ def main():

@main.command()
@click.argument("file_path")
@click.option("--warn", "-w", multiple=True)
@click.option("--skip", "-s", multiple=True)
@click.option("--verbose", "-v", count=True, help="Print performed checks to stdout.")
def check(file_path, verbose):
def check(file_path, warn, skip, verbose):
"""Lint and validate a (yml or tsv) metadata block file.
Loads the input file and performs a series of checks defined in the rules.py module.
Expand All @@ -106,7 +108,7 @@ def check(file_path, verbose):
are also performed.
"""
lint_violations = ViolationsByFile()
lint_conf = LintConfig()
lint_conf = LintConfig.from_cli_args(warn, skip)

if verbose:
print(f"Checking input file: {file_path}\n\n")
Expand Down Expand Up @@ -146,6 +148,8 @@ def check(file_path, verbose):
@main.command()
@click.argument("file_path")
@click.option("--verbose", "-v", count=True, help="Print performed checks to stdout.")
@click.option("--warn", "-w", multiple=True)
@click.option("--skip", "-s", multiple=True)
@click.option(
"--outfile", "-o", nargs=1, help="Path to where the output file will be written."
)
Expand All @@ -170,7 +174,7 @@ def convert(file_path, verbose, outfile):
print(f"Checking input file: {file_path}\n\n")

lint_violations = ViolationsByFile()
lint_conf = LintConfig()
lint_conf = LintConfig.from_cli_args(warn, skip)

input_type, file_ext_violations = guess_input_type(file_path)
lint_violations.extend_for(file_path, file_ext_violations)
Expand Down
17 changes: 17 additions & 0 deletions yml2block/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def __init__(self):
"""Create an empty config."""
self.overrides = dict()

@classmethod
def from_cli_args(cls, warn, skip):
"""Create config ussing warning and skip lists from CLI."""
conf = cls()
for warn_lint in warn:
lint = LINT_NAMES[warn_lint]
conf.warning(lint)
for skip_lint in skip:
lint = LINT_NAMES[skip_lint]
conf.skip(lint)
return conf

def get(self, lint):
"""Return an overridden lint, if present. Otherwise keep original lint."""
try:
Expand Down Expand Up @@ -343,3 +355,8 @@ def no_trailing_white_spaces(list_item, tsv_keyword, level=Level.ERROR):
)
)
return violations


LINT_NAMES = {
"ws": no_trailing_white_spaces,
}

0 comments on commit 85ec58b

Please sign in to comment.