4949else :
5050 BooleanOptionalAction = None
5151
52+ OPTION_OUTPUT_STDOUT = '-'
53+
5254
5355class Command :
5456 @classmethod
@@ -74,14 +76,20 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar
7476 action = 'store_true' ,
7577 dest = 'short_purls' ,
7678 default = False )
77- op .add_argument ('-o' , '--outfile' ,
79+ op .add_argument ('--outfile' , # DEPRECATED
80+ metavar = '<file>' ,
81+ help = 'DEPRECATED alias for "--output-file".' ,
82+ type = FileType ('wt' , encoding = 'utf8' ),
83+ dest = 'output_file' ,
84+ default = OPTION_OUTPUT_STDOUT )
85+ op .add_argument ('-o' , '--output-file' ,
7886 metavar = '<file>' ,
7987 help = 'Output file path for your SBOM'
80- ' (set to "- " to output to <stdout>)'
88+ f ' (set to "{ OPTION_OUTPUT_STDOUT } " to output to <stdout>)'
8189 ' (default: %(default)s)' ,
8290 type = FileType ('wt' , encoding = 'utf8' ),
83- dest = 'outfile ' ,
84- default = '-' )
91+ dest = 'output_file ' ,
92+ default = OPTION_OUTPUT_STDOUT )
8593 op .add_argument ('--schema-version' , # DEPRECATED
8694 metavar = '<version>' ,
8795 help = 'DEPRECATED alias for option "--spec-version".' ,
@@ -159,7 +167,7 @@ def make_argument_parser(cls, sco: ArgumentParser, **kwargs: Any) -> ArgumentPar
159167 # the arg keywords from __init__()
160168 'logger' , 'short_purls' , 'output_format' , 'spec_version' , 'output_reproducible' , 'should_validate' ,
161169 # the arg keywords from __call__()
162- 'outfile '
170+ 'output_file '
163171 }
164172
165173 @classmethod
@@ -232,10 +240,10 @@ def _validate(self, output: str) -> bool:
232240 self ._logger .debug ('result is schema-valid' )
233241 return True
234242
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 )
243+ def _write (self , output : str , output_file : TextIO ) -> int :
244+ self ._logger .info ('Writing to: %s' , output_file .name )
245+ written = output_file .write (output )
246+ self ._logger .debug ('Wrote %i bytes to %s' , written , output_file .name )
239247 return written
240248
241249 def _make_output (self , bom : 'Bom' ) -> str :
@@ -259,14 +267,14 @@ def _make_bom(self, **kwargs: Any) -> 'Bom':
259267 return self ._bbc (** self ._clean_kwargs (kwargs ))
260268
261269 def __call__ (self ,
262- outfile : TextIO ,
270+ output_file : TextIO ,
263271 ** kwargs : Any ) -> None :
264272 bom = self ._make_bom (** kwargs )
265273 self ._shorten_purls (bom )
266274 output = self ._make_output (bom )
267275 del bom
268276 self ._validate (output )
269- self ._write (output , outfile )
277+ self ._write (output , output_file )
270278
271279
272280def run (* , argv : Optional [Sequence [str ]] = None , ** kwargs : Any ) -> Union [int , NoReturn ]:
0 commit comments