Skip to content

Commit

Permalink
Use click for command line argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Nov 30, 2023
1 parent 7f71298 commit c3ae70b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = {file = "LICENSE"}
description = "Pixee CLI"
dependencies = [
"codemodder",
"click",
"prompt-toolkit"
]

Expand Down
44 changes: 15 additions & 29 deletions src/pixee/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from argparse import ArgumentParser, Namespace
import os
import subprocess

import click
from prompt_toolkit import prompt
from prompt_toolkit.completion.filesystem import PathCompleter
from rich.console import Console
Expand All @@ -11,12 +11,22 @@
# Enable overrides for local testing purposes
PYTHON_CODEMODDER = os.environ.get("PIXEE_PYTHON_CODEMODDER", "pixee-python-codemodder")

console = Console()

def run_fix(console: Console, args: Namespace):

@click.group()
def main():
console.print(logo, style="bold cyan")


@main.command()
@click.argument("path", nargs=1, required=False, type=click.Path(exists=True))
def fix(path):
"""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")
if not args.path:
args.path = prompt(
if not path:
path = prompt(
"Path to the project to fix: ",
complete_while_typing=True,
complete_in_thread=True,
Expand All @@ -25,31 +35,7 @@ def run_fix(console: Console, args: Namespace):
)

output_path = "results.codetf.json"
subprocess.run([PYTHON_CODEMODDER, args.path, "--output", output_path], check=True)


def main():
console = Console()
console.print(logo, style="bold cyan")

parser = ArgumentParser(description="Pixee CLI")
subparsers = parser.add_subparsers(dest="command", help="Commands")

fix = subparsers.add_parser("fix", help="Find and fix vulnerabilities")
fix.add_argument("path", nargs="?", help="Path to the project to fix")

subparsers.add_parser("triage", help="Triage findings")
subparsers.add_parser("remediate", help="Fix vulnerabilities from external tools")

args = parser.parse_args()

if not args.command:
parser.print_help()
return

match args.command:
case "fix":
run_fix(console, args)
subprocess.run([PYTHON_CODEMODDER, path, "--output", output_path], check=True)


if __name__ == "__main__":
Expand Down

0 comments on commit c3ae70b

Please sign in to comment.