Skip to content

Commit a0b90f9

Browse files
fmoessbauerUrist-McGit
authored andcommitted
feat(cli): allow to pass SBOM via stdin
For commands that take an SBOM as input, we add support to read it from stdin. This especially helps if the tool is run from a container, as then no bind-mounted input file is needed. Signed-off-by: Felix Moessbauer <[email protected]>
1 parent 3cabe3c commit a0b90f9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/debsbom/cli.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,22 @@ class SbomInput:
6262

6363
@classmethod
6464
def parser_add_sbom_input_args(cls, parser):
65-
parser.add_argument("bomin", help="sbom file to process", nargs="?")
65+
parser.add_argument(
66+
"bomin", help="sbom file to process ('-' to read SBOM from stdin)", nargs="?"
67+
)
68+
parser.add_argument(
69+
"-t",
70+
"--sbom-type",
71+
choices=["cdx", "spdx"],
72+
help="SBOM type to process (default: auto-detect)",
73+
)
6674

6775
@classmethod
6876
def get_sbom_resolver(cls, args):
77+
if args.bomin == "-":
78+
if not args.sbom_type:
79+
raise RuntimeError("If reading from stdin, the '--sbom-type' needs to be set")
80+
return PackageResolver.from_stream(sys.stdin, SBOMType.from_str(args.sbom_type))
6981
return PackageResolver.create(Path(args.bomin))
7082

7183
@classmethod

0 commit comments

Comments
 (0)