Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ The command line options are aligned to the standard Conan options.
```shellSession
$ cyclonedx-conan --help
usage: cyclonedx-conan [-h] [-if INSTALL_FOLDER] [-db [DRY_BUILD]]
[--exclude-dev] [-b [BUILD]] [-r REMOTE] [-u]
[--output FILE_PATH] [--exclude-dev]
[-b [BUILD]] [-r REMOTE] [-u]
[-l LOCKFILE] [--lockfile-out LOCKFILE_OUT]
[-e ENV_HOST] [-e:b ENV_BUILD] [-e:h ENV_HOST]
[-o OPTIONS_HOST] [-o:b OPTIONS_BUILD]
Expand All @@ -69,6 +70,8 @@ options:
If you specify both install-folder and any setting/option it will raise an error.
-db [DRY_BUILD], --dry-build [DRY_BUILD]
Apply the --build argument to output the information, as it would be done by the install command
--output FILE_PATH
Output file path for your SBOM (set to '-' to output to STDOUT)
--exclude-dev Exclude development dependencies from the BOM
-b [BUILD], --build [BUILD]
Given a build policy, return an ordered list of packages that would be built from sources during the install command
Expand Down
16 changes: 13 additions & 3 deletions src/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from conans.client.conan_api import Conan, ProfileData
from conans.client.command import Command as ConanCommand, OnceArgument, Extender, _add_common_install_arguments
from conans.client.graph.graph import DepsGraph, Node
from conans.client.output import ConanOutput, colorama_initialize
from conans.errors import ConanMigrationError, ConanException
from packageurl import PackageURL
from typing import Set
Expand Down Expand Up @@ -54,6 +55,11 @@ def get_arg_parser() -> argparse.ArgumentParser:
dry_build_help = ("Apply the --build argument to output the information, "
"as it would be done by the install command")
parser.add_argument("-db", "--dry-build", action=Extender, nargs="?", help=dry_build_help)
output_help='Output file path for your SBOM (set to \'-\' to output to STDOUT)'
parser.add_argument(
'--output', action='store', metavar='FILE_PATH', default="-", required=False,
help=output_help, dest='output_file'
)
exclude_dev_help = 'Exclude development dependencies from the BOM'
parser.add_argument(
'--exclude-dev', action='store_true',
Expand All @@ -71,7 +77,7 @@ def get_arg_parser() -> argparse.ArgumentParser:

def execute(self):
try:
conan_api, _, _ = Conan.factory()
conan_api = Conan(output=ConanOutput(sys.stderr, sys.stderr, colorama_initialize()))
except ConanMigrationError: # Error migrating
sys.exit(1)
except ConanException as e:
Expand Down Expand Up @@ -180,8 +186,12 @@ def execute(self):
dependencies['dependsOn'].append(str(dep_purl))
bom['dependencies'].append(dependencies)

print(json.dumps(bom, indent=2))

output = json.dumps(bom, indent=2)
if self._arguments.output_file == '-' or not self._arguments.output_file:
print(output)
else:
with open(self._arguments.output_file, "w") as file:
file.write(output)

def get_purl(remote, ref):
qualifiers = {
Expand Down