105 lines
2.7 KiB
Python
105 lines
2.7 KiB
Python
"""Argument parser for ShellGen CLI using argparse."""
|
|
|
|
import argparse
|
|
|
|
|
|
def create_parser() -> argparse.ArgumentParser:
|
|
"""Create the argument parser for ShellGen CLI.
|
|
|
|
Returns:
|
|
Configured ArgumentParser instance.
|
|
"""
|
|
parser = argparse.ArgumentParser(
|
|
prog="shellgen",
|
|
description="ShellGen - Convert natural language to shell commands using local LLMs",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
shellgen "find all python files in current directory"
|
|
shellgen "create a new git branch and switch to it"
|
|
shellgen "list all processes using more than 100MB memory"
|
|
shellgen --shell zsh "show me the disk usage sorted by size"
|
|
|
|
Supported shells: bash, zsh
|
|
""",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--version",
|
|
action="version",
|
|
version="%(prog)s 0.1.0",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--backend",
|
|
choices=["ollama", "llama_cpp"],
|
|
help="LLM backend to use (default: ollama)",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--shell",
|
|
choices=["bash", "zsh"],
|
|
help="Target shell for command generation",
|
|
)
|
|
|
|
subparsers = parser.add_subparsers(
|
|
dest="command",
|
|
title="commands",
|
|
description="Available commands",
|
|
)
|
|
|
|
generate_parser = subparsers.add_parser(
|
|
"generate",
|
|
help="Generate a shell command from natural language",
|
|
)
|
|
generate_parser.add_argument(
|
|
"description",
|
|
help="Natural language description of what you want to do",
|
|
)
|
|
generate_parser.add_argument(
|
|
"--execute",
|
|
action="store_true",
|
|
help="Execute the generated command",
|
|
)
|
|
generate_parser.add_argument(
|
|
"--auto-execute",
|
|
action="store_true",
|
|
help="Automatically execute safe commands without confirmation",
|
|
)
|
|
generate_parser.add_argument(
|
|
"--force",
|
|
action="store_true",
|
|
help="Force execution even for potentially dangerous commands",
|
|
)
|
|
|
|
history_parser = subparsers.add_parser(
|
|
"history",
|
|
help="Show command generation history",
|
|
)
|
|
history_parser.add_argument(
|
|
"--limit",
|
|
type=int,
|
|
default=20,
|
|
help="Maximum number of entries to show (default: 20)",
|
|
)
|
|
|
|
feedback_parser = subparsers.add_parser(
|
|
"feedback",
|
|
help="Submit feedback for a generated command",
|
|
)
|
|
feedback_parser.add_argument(
|
|
"id",
|
|
type=int,
|
|
help="ID of the history entry to provide feedback for",
|
|
)
|
|
feedback_parser.add_argument(
|
|
"--corrected",
|
|
help="The corrected command",
|
|
)
|
|
feedback_parser.add_argument(
|
|
"--feedback",
|
|
help="Additional feedback or notes",
|
|
)
|
|
|
|
return parser
|