diff options
| author | Louis Burda <dev@sinitax.com> | 2026-01-30 03:04:01 +0100 |
|---|---|---|
| committer | Louis Burda <dev@sinitax.com> | 2026-01-30 03:04:01 +0100 |
| commit | f6487c615cff023db1574e2c23db78bf02a43709 (patch) | |
| tree | 8a0e793a8ea28b2a5eef5dcd509b6c6a2466ee1c /src/nvd/cli/main.py | |
| download | nvdb-py-main.tar.gz nvdb-py-main.zip | |
Diffstat (limited to 'src/nvd/cli/main.py')
| -rw-r--r-- | src/nvd/cli/main.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/nvd/cli/main.py b/src/nvd/cli/main.py new file mode 100644 index 0000000..fc90fe5 --- /dev/null +++ b/src/nvd/cli/main.py @@ -0,0 +1,72 @@ +"""Main CLI entry point.""" + +import sys + +import typer +from rich.console import Console +from rich.panel import Panel +from rich.text import Text + +from .commands import config, cpe, cve + +# Enable -h as shorthand for --help +CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]} + +app = typer.Typer( + name="nvdb", + help="NVD API CLI - Query the US National Vulnerability Database", + add_completion=False, + rich_markup_mode="rich", + context_settings=CONTEXT_SETTINGS, +) + +# Console for stderr (help messages, examples) +console = Console(stderr=True) + + +def show_examples() -> None: + """Show usage examples.""" + examples = Text() + examples.append("Quick Examples:\n\n", style="bold cyan") + examples.append(" # Get a specific CVE\n", style="dim") + examples.append(" nvdb cve get CVE-2021-44228\n\n", style="green") + examples.append(" # Search for critical vulnerabilities\n", style="dim") + examples.append(" nvdb cve search --severity CRITICAL --limit 10\n\n", style="green") + examples.append(" # Search CVEs in CISA KEV catalog\n", style="dim") + examples.append(" nvdb cve search --has-kev --limit 20\n\n", style="green") + examples.append(" # Search CPEs\n", style="dim") + examples.append(" nvdb cpe search --keyword 'windows 10'\n\n", style="green") + examples.append(" # Configure API key\n", style="dim") + examples.append(" nvdb config set-api-key YOUR_API_KEY\n\n", style="green") + examples.append("Get help for specific commands:\n", style="bold yellow") + examples.append(" nvdb cve --help\n", style="blue") + examples.append(" nvdb cpe --help\n", style="blue") + examples.append(" nvdb config --help\n", style="blue") + + console.print(Panel(examples, title="[bold]nvdb - NVD API CLI[/bold]", border_style="blue")) + + +@app.callback(invoke_without_command=True) +def main_callback(ctx: typer.Context) -> None: + """Main callback to show examples when no command is provided.""" + if ctx.invoked_subcommand is None and len(sys.argv) == 1: + show_examples() + raise typer.Exit() + + +# Register command groups +app.add_typer(cve.app, name="cve", help="CVE (vulnerability) commands") +app.add_typer(cpe.app, name="cpe", help="CPE (product) commands") +app.add_typer(config.app, name="config", help="Configuration commands") + + +@app.command() +def version() -> None: + """Show version information.""" + from .. import __version__ + + console.print(f"nvdb-py version: {__version__}") + + +if __name__ == "__main__": + app() |
