Skip to content

Commit bbae05f

Browse files
authored
feat: deprecate CLI switch --schema-version; use new --spec-version instead (#871)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 309bf5c commit bbae05f

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

cyclonedx_py/_internal/cli.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 option "--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,17 +213,17 @@ 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)
218225
self._logger.error('The result is invalid to schema '
219-
f'{self._schema_version.to_version()}/{self._output_format.name}')
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&'
@@ -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':

docs/usage.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Example usage: save SBOM in CycloneDX 1.6 XML format, generated from current pyt
3535

3636
.. code-block:: shell
3737
38-
cyclonedx-py environment --outfile my-sbom.xml --schema-version 1.6 --output-format XML
38+
cyclonedx-py environment --outfile my-sbom.xml --spec-version 1.6 --output-format XML
3939
4040
4141
For Python (virtual) environment
@@ -85,7 +85,9 @@ The full documentation can be issued by running with ``environment --help``:
8585
Output file path for your SBOM
8686
(set to "-" to output to STDOUT)
8787
(default: -)
88-
--sv <version>, --schema-version <version>
88+
--schema-version <version>
89+
DEPRECATED alias for "--spec-version"
90+
--sv <version>, --spec-version <version>
8991
The CycloneDX schema version for your SBOM
9092
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
9193
(default: 1.5)
@@ -256,7 +258,9 @@ The full documentation can be issued by running with ``pipenv --help``:
256258
Output file path for your SBOM
257259
(set to "-" to output to <stdout>)
258260
(default: -)
259-
--sv <version>, --schema-version <version>
261+
--schema-version <version>
262+
DEPRECATED alias for "--spec-version"
263+
--sv <version>, --spec-version <version>
260264
The CycloneDX schema version for your SBOM
261265
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
262266
(default: 1.5)
@@ -331,7 +335,9 @@ The full documentation can be issued by running with ``poetry --help``:
331335
Output file path for your SBOM
332336
(set to "-" to output to <stdout>)
333337
(default: -)
334-
--sv <version>, --schema-version <version>
338+
--schema-version <version>
339+
DEPRECATED alias for "--spec-version"
340+
--sv <version>, --spec-version <version>
335341
The CycloneDX schema version for your SBOM
336342
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
337343
(default: 1.5)
@@ -402,7 +408,9 @@ The full documentation can be issued by running with ``requirements --help``:
402408
Output file path for your SBOM
403409
(set to "-" to output to <stdout>)
404410
(default: -)
405-
--sv <version>, --schema-version <version>
411+
--schema-version <version>
412+
DEPRECATED alias for "--spec-version"
413+
--sv <version>, --spec-version <version>
406414
The CycloneDX schema version for your SBOM
407415
{choices: 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0}
408416
(default: 1.5)

tests/unit/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder:
7676
command = Command(
7777
logger=self.__make_fresh_logger(logs),
7878
short_purls=short_purls,
79-
schema_version=SchemaVersion.V1_4,
79+
spec_version=SchemaVersion.V1_4,
8080
output_format=OutputFormat.JSON,
8181
should_validate=True,
8282
output_reproducible=True,
@@ -100,7 +100,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder:
100100
command = Command(
101101
logger=self.__make_fresh_logger(logs),
102102
short_purls=False,
103-
schema_version=SchemaVersion.V1_4,
103+
spec_version=SchemaVersion.V1_4,
104104
output_format=OutputFormat.JSON,
105105
output_reproducible=False,
106106
should_validate=True,
@@ -123,7 +123,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> BomBuilder:
123123
command = Command(
124124
logger=self.__make_fresh_logger(logs, logging.WARNING),
125125
short_purls=False,
126-
schema_version=SchemaVersion.V1_4,
126+
spec_version=SchemaVersion.V1_4,
127127
output_format=OutputFormat.JSON,
128128
should_validate=False,
129129
output_reproducible=False,

0 commit comments

Comments
 (0)