Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 19 additions & 12 deletions cyclonedx_py/_internal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar
type=FileType('wt', encoding='utf8'),
dest='outfile',
default='-')
op.add_argument('--sv', '--schema-version',
op.add_argument('--schema-version', # DEPRECATED
metavar='<version>',
help='The CycloneDX schema version for your SBOM'
help='DEPRECATED alias for option "--spec-version".',
dest='spec_version',
choices=SchemaVersion,
type=SchemaVersion.from_version,
default=SchemaVersion.V1_5.to_version())
op.add_argument('--sv', '--spec-version',
metavar='<version>',
help='The CycloneDX spec version for your SBOM'
f' {{choices: {", ".join(sorted((v.to_version() for v in SchemaVersion), reverse=True))}}}'
' (default: %(default)s)',
dest='schema_version',
dest='spec_version',
choices=SchemaVersion,
type=SchemaVersion.from_version,
default=SchemaVersion.V1_5.to_version())
Expand Down Expand Up @@ -150,7 +157,7 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar

__OWN_ARGS = {
# the arg keywords from __init__()
'logger', 'short_purls', 'output_format', 'schema_version', 'output_reproducible', 'should_validate',
'logger', 'short_purls', 'output_format', 'spec_version', 'output_reproducible', 'should_validate',
# the arg keywords from __call__()
'outfile'
}
Expand All @@ -163,15 +170,15 @@ def __init__(self, *,
logger: logging.Logger,
short_purls: bool,
output_format: OutputFormat,
schema_version: SchemaVersion,
spec_version: SchemaVersion,
output_reproducible: bool,
should_validate: bool,
_bbc: Type['BomBuilder'],
**kwargs: Any) -> None:
self._logger = logger
self._short_purls = short_purls
self._output_format = output_format
self._schema_version = schema_version
self._spec_version = spec_version
self._output_reproducible = output_reproducible
self._should_validate = should_validate
self._bbc = _bbc(**self._clean_kwargs(kwargs),
Expand Down Expand Up @@ -206,17 +213,17 @@ def _validate(self, output: str) -> bool:
self._logger.warning('Validation skipped.')
return False

self._logger.info('Validating result to schema: %s/%s',
self._schema_version.to_version(), self._output_format.name)
self._logger.info('Validating result to spec: %s/%s',
self._spec_version.to_version(), self._output_format.name)

validation_error = make_schemabased_validator(
self._output_format,
self._schema_version
self._spec_version
).validate_str(output)
if validation_error:
self._logger.debug('Validation Errors: %r', validation_error.data)
self._logger.error('The result is invalid to schema '
f'{self._schema_version.to_version()}/{self._output_format.name}')
f'{self._spec_version.to_version()}/{self._output_format.name}')
self._logger.warning('Please report the issue and provide all input data to: '
'https://github.com/CycloneDX/cyclonedx-python/issues/new?'
'template=ValidationError-report.md&'
Expand All @@ -232,7 +239,7 @@ def _write(self, output: str, outfile: TextIO) -> int:
return written

def _make_output(self, bom: 'Bom') -> str:
self._logger.info('Serializing SBOM: %s/%s', self._schema_version.to_version(), self._output_format.name)
self._logger.info('Serializing SBOM: %s/%s', self._spec_version.to_version(), self._output_format.name)

if self._output_reproducible:
bom.metadata.properties.add(Property(name=PropertyName.Reproducible.value,
Expand All @@ -244,7 +251,7 @@ def _make_output(self, bom: 'Bom') -> str:
return make_outputter(
bom,
self._output_format,
self._schema_version
self._spec_version
).output_as_string(indent=2)

def _make_bom(self, **kwargs: Any) -> 'Bom':
Expand Down
18 changes: 13 additions & 5 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Example usage: save SBOM in CycloneDX 1.6 XML format, generated from current pyt

.. code-block:: shell

cyclonedx-py environment --outfile my-sbom.xml --schema-version 1.6 --output-format XML
cyclonedx-py environment --outfile my-sbom.xml --spec-version 1.6 --output-format XML


For Python (virtual) environment
Expand Down Expand Up @@ -85,7 +85,9 @@ The full documentation can be issued by running with ``environment --help``:
Output file path for your SBOM
(set to "-" to output to STDOUT)
(default: -)
--sv <version>, --schema-version <version>
--schema-version <version>
DEPRECATED alias for "--spec-version"
--sv <version>, --spec-version <version>
The CycloneDX schema version for your SBOM
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
(default: 1.5)
Expand Down Expand Up @@ -256,7 +258,9 @@ The full documentation can be issued by running with ``pipenv --help``:
Output file path for your SBOM
(set to "-" to output to <stdout>)
(default: -)
--sv <version>, --schema-version <version>
--schema-version <version>
DEPRECATED alias for "--spec-version"
--sv <version>, --spec-version <version>
The CycloneDX schema version for your SBOM
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
(default: 1.5)
Expand Down Expand Up @@ -331,7 +335,9 @@ The full documentation can be issued by running with ``poetry --help``:
Output file path for your SBOM
(set to "-" to output to <stdout>)
(default: -)
--sv <version>, --schema-version <version>
--schema-version <version>
DEPRECATED alias for "--spec-version"
--sv <version>, --spec-version <version>
The CycloneDX schema version for your SBOM
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
(default: 1.5)
Expand Down Expand Up @@ -402,7 +408,9 @@ The full documentation can be issued by running with ``requirements --help``:
Output file path for your SBOM
(set to "-" to output to <stdout>)
(default: -)
--sv <version>, --schema-version <version>
--schema-version <version>
DEPRECATED alias for "--spec-version"
--sv <version>, --spec-version <version>
The CycloneDX schema version for your SBOM
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
(default: 1.5)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder:
command = Command(
logger=self.__make_fresh_logger(logs),
short_purls=short_purls,
schema_version=SchemaVersion.V1_4,
spec_version=SchemaVersion.V1_4,
output_format=OutputFormat.JSON,
should_validate=True,
output_reproducible=True,
Expand All @@ -100,7 +100,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder:
command = Command(
logger=self.__make_fresh_logger(logs),
short_purls=False,
schema_version=SchemaVersion.V1_4,
spec_version=SchemaVersion.V1_4,
output_format=OutputFormat.JSON,
output_reproducible=False,
should_validate=True,
Expand All @@ -123,7 +123,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder:
command = Command(
logger=self.__make_fresh_logger(logs, logging.WARNING),
short_purls=False,
schema_version=SchemaVersion.V1_4,
spec_version=SchemaVersion.V1_4,
output_format=OutputFormat.JSON,
should_validate=False,
output_reproducible=False,
Expand Down