Skip to content

Commit 5af7e19

Browse files
committed
Merge main branch and resolve argparse conflict
- Update help text to use argparse format from main - Include new search keybindings (/, n, N) - Update package view keybinding from n to p
2 parents 430a091 + 9b430f1 commit 5af7e19

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

grummage.py

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
import argparse
23
import json
34
import os
45
import subprocess
@@ -819,42 +820,43 @@ def explain_vulnerability_worker(self, vuln_id, detailed_text):
819820

820821
def main():
821822
"""Main entry point for the grummage CLI."""
822-
# Handle help first, regardless of argument count
823-
if len(sys.argv) > 1 and sys.argv[1] in ['--help', '-h', 'help']:
824-
print("Grummage - Interactive terminal frontend for Grype to view vulnerabilities")
825-
print("")
826-
print("Usage: grummage <sbom-file>")
827-
print("")
828-
print("Navigation:")
829-
print(" • Arrow keys or h/j/k/l - Navigate")
830-
print(" • Enter - Select item")
831-
print("")
832-
print("Views:")
833-
print(" • p - View by Package name")
834-
print(" • t - View by Type")
835-
print(" • v - View by Vulnerability")
836-
print(" • s - View by Severity")
837-
print("")
838-
print("Search:")
839-
print(" • / - Search within current view")
840-
print(" • n - Find next result")
841-
print(" • N - Find previous result")
842-
print("")
843-
print("Actions:")
844-
print(" • e - Explain vulnerability (when available)")
845-
print(" • q - Quit")
846-
print("")
847-
print("Example:")
848-
print(" grummage my-app.spdx.json")
849-
sys.exit(0)
850-
851-
if len(sys.argv) != 2:
852-
print("Usage: grummage <sbom-file>")
853-
print("Use 'grummage --help' for more information")
854-
sys.exit(1)
855-
856-
sbom_file = sys.argv[1]
857-
823+
parser = argparse.ArgumentParser(
824+
prog="grummage",
825+
description="Interactive terminal frontend for Grype to view vulnerabilities",
826+
epilog="Example: grummage my-app.spdx.json",
827+
formatter_class=argparse.RawDescriptionHelpFormatter
828+
)
829+
830+
parser.add_argument(
831+
"sbom_file",
832+
help="Path to the SBOM file to analyze"
833+
)
834+
835+
# Add custom help text for navigation with updated keybindings
836+
parser.epilog = """Navigation:
837+
• Arrow keys or h/j/k/l - Navigate
838+
• Enter - Select item
839+
840+
Views:
841+
• p - View by Package name
842+
• v - View by Vulnerability
843+
• t - View by Type
844+
• s - View by Severity
845+
846+
Search:
847+
• / - Search within current view
848+
• n - Find next result
849+
• N - Find previous result
850+
851+
Actions:
852+
• e - Explain vulnerability (when available)
853+
• q - Quit
854+
855+
Example:
856+
grummage my-app.spdx.json"""
857+
858+
args = parser.parse_args()
859+
sbom_file = args.sbom_file
858860
if not is_grype_installed():
859861
if prompt_install_grype():
860862
install_grype()
@@ -863,8 +865,8 @@ def main():
863865
"The grype binary is not located in $PATH and the option to install was deferred."
864866
)
865867
sys.exit(0)
866-
867-
Grummage(sbom_file).run()
868+
869+
Grummage(args.sbom_file).run()
868870

869871
if __name__ == "__main__":
870872
main()

0 commit comments

Comments
 (0)