diff --git a/pyproject.toml b/pyproject.toml index a44b8ac..d522c2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ license = {file = "LICENSE"} description = "Pixee CLI" dependencies = [ "codemodder", + "click", "prompt-toolkit" ] diff --git a/src/pixee/cli.py b/src/pixee/cli.py index 2ed6ba8..f55b126 100644 --- a/src/pixee/cli.py +++ b/src/pixee/cli.py @@ -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 @@ -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, @@ -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__":