Skip to content

Commit

Permalink
Add --path-include and --path-exclude CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Dec 12, 2023
1 parent 130a43f commit 9d12698
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/pixee/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def validate_codemods(ctx, param, value) -> list[str]:
return given_codemods


def parse_path_patterns(ctx, param, value) -> list[str]:
del ctx, param

if not value:
return value

return value.split(",")


def print_logo():
lines = logo.split("\n")
top_lines, bottom_lines = lines[: len(lines) // 2], lines[len(lines) // 2 :]
Expand Down Expand Up @@ -125,11 +134,17 @@ def run_codemodder(
codemodder: str,
path,
codemods: list[Codemod],
path_include: list[str],
path_exclude: list[str],
dry_run: bool,
verbose: int,
):
common_codemodder_args = ["--dry-run"] if dry_run else []
common_codemodder_args.extend(["--codemod-include", ",".join(map(str, codemods))])
if path_include:
common_codemodder_args.extend(["--path-include", ",".join(path_include)])
if path_exclude:
common_codemodder_args.extend(["--path-exclude", ",".join(path_exclude)])
if verbose == 0 or verbose > 1:
common_codemodder_args.append("--verbose")

Expand Down Expand Up @@ -184,6 +199,16 @@ def triage():
callback=validate_codemods,
help="Comma-separated list of codemods to skip",
)
@click.option(
"--path-include",
callback=parse_path_patterns,
help="Comma-separated list of path patterns to include",
)
@click.option(
"--path-exclude",
callback=parse_path_patterns,
help="Comma-separated list of path patterns to exclude",
)
@click.option(
"--explain",
is_flag=True,
Expand All @@ -205,6 +230,8 @@ def fix(
verbose,
codemod_include,
codemod_exclude,
path_include,
path_exclude,
):
"""Find problems and harden your code"""
if list_codemods:
Expand Down Expand Up @@ -286,6 +313,8 @@ def fix(
codemodder,
path,
codemods_by_lang,
path_include,
path_exclude,
dry_run,
verbose,
)
Expand Down

0 comments on commit 9d12698

Please sign in to comment.