Skip to content

Commit aa7b846

Browse files
committed
deprecate CLI switch --schema-version; use new --spec-version instead
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 309bf5c commit aa7b846

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

cyclonedx_py/_internal/cli.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import logging
1919
import sys
20-
from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter
20+
from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter, SUPPRESS as ARG_SUPPRESS
2121
from itertools import chain
2222
from typing import TYPE_CHECKING, Any, Dict, List, NoReturn, Optional, Sequence, TextIO, Type, Union
2323

@@ -82,12 +82,19 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar
8282
type=FileType('wt', encoding='utf8'),
8383
dest='outfile',
8484
default='-')
85-
op.add_argument('--sv', '--schema-version',
85+
op.add_argument('--schema-version', # DEPRECATED
8686
metavar='<version>',
87-
help='The CycloneDX schema version for your SBOM'
87+
help='DEPRECATED alias for "--spec-version"',
88+
dest='spec_version',
89+
choices=SchemaVersion,
90+
type=SchemaVersion.from_version,
91+
default=SchemaVersion.V1_5.to_version())
92+
op.add_argument('--sv', '--spec-version',
93+
metavar='<version>',
94+
help='The CycloneDX spec version for your SBOM'
8895
f' {{choices: {", ".join(sorted((v.to_version() for v in SchemaVersion), reverse=True))}}}'
8996
' (default: %(default)s)',
90-
dest='schema_version',
97+
dest='spec_version',
9198
choices=SchemaVersion,
9299
type=SchemaVersion.from_version,
93100
default=SchemaVersion.V1_5.to_version())
@@ -150,7 +157,7 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar
150157

151158
__OWN_ARGS = {
152159
# the arg keywords from __init__()
153-
'logger', 'short_purls', 'output_format', 'schema_version', 'output_reproducible', 'should_validate',
160+
'logger', 'short_purls', 'output_format', 'spec_version', 'output_reproducible', 'should_validate',
154161
# the arg keywords from __call__()
155162
'outfile'
156163
}
@@ -163,15 +170,15 @@ def __init__(self, *,
163170
logger: logging.Logger,
164171
short_purls: bool,
165172
output_format: OutputFormat,
166-
schema_version: SchemaVersion,
173+
spec_version: SchemaVersion,
167174
output_reproducible: bool,
168175
should_validate: bool,
169176
_bbc: Type['BomBuilder'],
170177
**kwargs: Any) -> None:
171178
self._logger = logger
172179
self._short_purls = short_purls
173180
self._output_format = output_format
174-
self._schema_version = schema_version
181+
self._spec_version = spec_version
175182
self._output_reproducible = output_reproducible
176183
self._should_validate = should_validate
177184
self._bbc = _bbc(**self._clean_kwargs(kwargs),
@@ -206,23 +213,23 @@ def _validate(self, output: str) -> bool:
206213
self._logger.warning('Validation skipped.')
207214
return False
208215

209-
self._logger.info('Validating result to schema: %s/%s',
210-
self._schema_version.to_version(), self._output_format.name)
216+
self._logger.info('Validating result to spec: %s/%s',
217+
self._spec_version.to_version(), self._output_format.name)
211218

212219
validation_error = make_schemabased_validator(
213220
self._output_format,
214-
self._schema_version
221+
self._spec_version
215222
).validate_str(output)
216223
if validation_error:
217224
self._logger.debug('Validation Errors: %r', validation_error.data)
218-
self._logger.error('The result is invalid to schema '
219-
f'{self._schema_version.to_version()}/{self._output_format.name}')
225+
self._logger.error('The result is invalid to spec '
226+
f'{self._spec_version.to_version()}/{self._output_format.name}')
220227
self._logger.warning('Please report the issue and provide all input data to: '
221228
'https://github.com/CycloneDX/cyclonedx-python/issues/new?'
222229
'template=ValidationError-report.md&'
223230
'labels=ValidationError&title=%5BValidationError%5D')
224-
raise ValueError('result is schema-invalid')
225-
self._logger.debug('result is schema-valid')
231+
raise ValueError('result is spec-invalid')
232+
self._logger.debug('result is spec-valid')
226233
return True
227234

228235
def _write(self, output: str, outfile: TextIO) -> int:
@@ -232,7 +239,7 @@ def _write(self, output: str, outfile: TextIO) -> int:
232239
return written
233240

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

237244
if self._output_reproducible:
238245
bom.metadata.properties.add(Property(name=PropertyName.Reproducible.value,
@@ -244,7 +251,7 @@ def _make_output(self, bom: 'Bom') -> str:
244251
return make_outputter(
245252
bom,
246253
self._output_format,
247-
self._schema_version
254+
self._spec_version
248255
).output_as_string(indent=2)
249256

250257
def _make_bom(self, **kwargs: Any) -> 'Bom':

0 commit comments

Comments
 (0)