Skip to content

Commit 2e4396a

Browse files
committed
cli: added version info in help
1 parent 4111f13 commit 2e4396a

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

cve_search_cli.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import requests
33
import argparse
44
import sys
5+
import os
6+
import subprocess
7+
from pathlib import Path
58
from datetime import datetime
69
try:
710
from rich import print
@@ -25,6 +28,33 @@
2528
}
2629
)
2730

31+
32+
def get_version() -> str:
33+
version = os.environ.get("SNAP_VERSION")
34+
if version:
35+
return version
36+
37+
version = os.environ.get("CVECLI_VERSION")
38+
if version:
39+
return version
40+
41+
try:
42+
script_dir = Path(__file__).resolve().parent
43+
result = subprocess.run(
44+
["git", "-C", str(script_dir), "describe", "--tags", "--always"],
45+
capture_output=True,
46+
text=True,
47+
check=False,
48+
timeout=1,
49+
)
50+
described = (result.stdout or "").strip()
51+
if described:
52+
return described
53+
except Exception:
54+
pass
55+
56+
return "unknown"
57+
2858
def format_date(date_str):
2959
if not date_str:
3060
return "N/A"
@@ -150,9 +180,11 @@ def interactive_menu():
150180
console.print("[bold red]Invalid choice. Please try again.")
151181

152182
def main():
153-
parser = argparse.ArgumentParser(description="CVE Search CLI Tool")
183+
version = get_version()
184+
parser = argparse.ArgumentParser(description=f"CVE Search CLI Tool (version {version})")
154185
parser.add_argument("--id", help="Search CVE by ID, e.g., CVE-2024-12345")
155186
parser.add_argument("--keyword", help="Search CVEs by keyword in description")
187+
parser.add_argument("--version", action="version", version=f"cvecli {version}")
156188
args = parser.parse_args()
157189

158190
if args.id:

0 commit comments

Comments
 (0)