Skip to content

Commit 8a06b34

Browse files
committed
feat: deprecate CLI switch --outfile; use new --output-file instead
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent bbae05f commit 8a06b34

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

cyclonedx_py/_internal/cli.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
else:
5050
BooleanOptionalAction = None
5151

52+
OPTION_OUTPUT_STDOUT='-'
5253

5354
class Command:
5455
@classmethod
@@ -74,14 +75,20 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar
7475
action='store_true',
7576
dest='short_purls',
7677
default=False)
77-
op.add_argument('-o', '--outfile',
78+
op.add_argument('--outfile', # DEPRECATED
79+
metavar='<file>',
80+
help='DEPRECATED alias for "--output-file".',
81+
type=FileType('wt', encoding='utf8'),
82+
dest='output_file',
83+
default=OPTION_OUTPUT_STDOUT)
84+
op.add_argument('-o', '--output-file',
7885
metavar='<file>',
7986
help='Output file path for your SBOM'
80-
' (set to "-" to output to <stdout>)'
87+
f' (set to "{OPTION_OUTPUT_STDOUT}" to output to <stdout>)'
8188
' (default: %(default)s)',
8289
type=FileType('wt', encoding='utf8'),
83-
dest='outfile',
84-
default='-')
90+
dest='output_file',
91+
default=OPTION_OUTPUT_STDOUT)
8592
op.add_argument('--schema-version', # DEPRECATED
8693
metavar='<version>',
8794
help='DEPRECATED alias for option "--spec-version".',
@@ -159,7 +166,7 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar
159166
# the arg keywords from __init__()
160167
'logger', 'short_purls', 'output_format', 'spec_version', 'output_reproducible', 'should_validate',
161168
# the arg keywords from __call__()
162-
'outfile'
169+
'output_file'
163170
}
164171

165172
@classmethod
@@ -232,10 +239,10 @@ def _validate(self, output: str) -> bool:
232239
self._logger.debug('result is schema-valid')
233240
return True
234241

235-
def _write(self, output: str, outfile: TextIO) -> int:
236-
self._logger.info('Writing to: %s', outfile.name)
237-
written = outfile.write(output)
238-
self._logger.debug('Wrote %i bytes to %s', written, outfile.name)
242+
def _write(self, output: str, output_file: TextIO) -> int:
243+
self._logger.info('Writing to: %s', output_file.name)
244+
written = output_file.write(output)
245+
self._logger.debug('Wrote %i bytes to %s', written, output_file.name)
239246
return written
240247

241248
def _make_output(self, bom: 'Bom') -> str:
@@ -259,14 +266,14 @@ def _make_bom(self, **kwargs: Any) -> 'Bom':
259266
return self._bbc(**self._clean_kwargs(kwargs))
260267

261268
def __call__(self,
262-
outfile: TextIO,
269+
output_file: TextIO,
263270
**kwargs: Any) -> None:
264271
bom = self._make_bom(**kwargs)
265272
self._shorten_purls(bom)
266273
output = self._make_output(bom)
267274
del bom
268275
self._validate(output)
269-
self._write(output, outfile)
276+
self._write(output, output_file)
270277

271278

272279
def run(*, argv: Optional[Sequence[str]] = None, **kwargs: Any) -> Union[int, NoReturn]:

0 commit comments

Comments
 (0)