Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for writing to stdout #283

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion cmd/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
rootCmd.Flags().StringP("path", "p", ".", "the path to package file or the path to a directory which will be recursively analyzed for the package files (default '.')")
rootCmd.Flags().BoolP("include-license-text", "i", false, " Include full license text (default: false)")
rootCmd.Flags().StringP("schema", "s", "2.2", "<version> Target schema version (default: '2.2')")
rootCmd.Flags().StringP("output-dir", "o", ".", "<output> directory to Write SPDX to file (default: current directory)")
rootCmd.Flags().StringP("output-dir", "o", "", "<output> directory to Write SPDX to file (default: stdout)")
rootCmd.Flags().StringP("format", "f", "spdx", "output file format (default: spdx)")
rootCmd.Flags().StringP("global-settings", "g", "", "Alternate path for the global settings file for Java Maven (default 'mvn settings.xml')")

Expand Down
7 changes: 6 additions & 1 deletion pkg/handler/spdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func getFiletypeForOutputFormat(outputFormat models.OutputFormat) string {

// NewSPDX ...
func NewSPDX(settings SPDXSettings) (Handler, error) {
if !helper.Exists(settings.OutputDir) {
if settings.OutputDir != "" && !helper.Exists(settings.OutputDir) {
return nil, errOutputDirDoesNotExist
}

Expand Down Expand Up @@ -84,6 +84,11 @@ func (sh *spdxHandler) Run() error {
outputFile := filepath.Join(sh.config.OutputDir, filename)
globalSettingFile := sh.config.GlobalSettingFile

// case when no outputDir was supplied, and output needs to be written to stdout.
if sh.config.OutputDir == "" {
outputFile = "/dev/stdout"
}

log.Infof("Running generator for Module Manager: `%s` with output `%s`", plugin.Slug, outputFile)
if err := mm.Run(); err != nil {
sh.errors[plugin.Slug] = err
Expand Down