Skip to content

Commit

Permalink
Pass dry-run flag
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Nov 30, 2023
1 parent de1c665 commit e348049
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/pixee/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,23 @@ def main():
console.print(logo, style="bold cyan")


def run_codemodder(codemodder, path, dry_run):
common_codemodder_args = ["--dry-run"] if dry_run else []

codetf = tempfile.NamedTemporaryFile()
subprocess.run(
[codemodder, "--output", codetf.name, path] + common_codemodder_args,
stderr=subprocess.DEVNULL,
check=True,
)

return codetf


@main.command()
@click.argument("path", nargs=1, required=False, type=click.Path(exists=True))
def fix(path):
@click.option("--dry-run", is_flag=True, help="Don't write changes to disk")
def fix(path, dry_run):
"""Find and fix vulnerabilities in your project"""
console.print("Welcome to Pixee!", style="bold")
console.print("Let's find and fix vulnerabilities in your project.", style="bold")
Expand All @@ -38,20 +52,16 @@ def fix(path):
default=os.getcwd(),
)

python_codetf = tempfile.NamedTemporaryFile()
console.print("Dry run:", dry_run, style="bold")

# TODO: better file glob patterns
if python_files := glob(str(Path(path) / "**" / "*.py"), recursive=True):
console.print("Running Python codemods...", style="bold")
subprocess.run(
[PYTHON_CODEMODDER, "--output", python_codetf.name, path], check=True
)
python_codetf = run_codemodder(PYTHON_CODEMODDER, path, dry_run)

java_codetf = tempfile.NamedTemporaryFile()
if java_files := glob(str(Path(path) / "**" / "*.java"), recursive=True):
console.print("Running Java codemods...", style="bold")
subprocess.run(
[JAVA_CODEMODDER, "--output", java_codetf.name, path], check=True
)
java_codetf = run_codemodder(JAVA_CODEMODDER, path, dry_run)


@main.command()
Expand Down

0 comments on commit e348049

Please sign in to comment.