diff --git a/cmd/component.go b/cmd/component.go index 03c28190..121bc08e 100644 --- a/cmd/component.go +++ b/cmd/component.go @@ -184,18 +184,17 @@ func ListComponents(writer io.Writer, persistentFlags utils.PersistentCommandFla getLogger().Infof("Outputting listing (`%s` format)...", format) switch format { case FORMAT_TEXT: - DisplayComponentListText(document, writer) + err = DisplayComponentListText(document, writer) case FORMAT_CSV: - DisplayComponentListCSV(document, writer) + err = DisplayComponentListCSV(document, writer) case FORMAT_MARKDOWN: - DisplayComponentListMarkdown(document, writer) + err = DisplayComponentListMarkdown(document, writer) default: // Default to Text output for anything else (set as flag default) getLogger().Warningf("Listing not supported for `%s` format; defaulting to `%s` format...", format, FORMAT_TEXT) - DisplayComponentListText(document, writer) + err = DisplayComponentListText(document, writer) } - return } diff --git a/cmd/license_list.go b/cmd/license_list.go index 28bb3992..d1689a9e 100644 --- a/cmd/license_list.go +++ b/cmd/license_list.go @@ -226,7 +226,7 @@ func ListLicenses(writer io.Writer, policyConfig *schema.LicensePolicyConfig, // Default to JSON output for anything else getLogger().Warningf("Listing not supported for `%s` format; defaulting to `%s` format...", format, FORMAT_JSON) - DisplayLicenseListJson(document, writer, licenseFlags) + err = DisplayLicenseListJson(document, writer, licenseFlags) } return } @@ -298,6 +298,7 @@ func DisplayLicenseListText(bom *schema.BOM, writer io.Writer, flags utils.Licen for _, licenseName := range licenseKeys { arrLicenseInfo, _ := bom.LicenseMap.Get(licenseName) + // Format each LicenseInfo as a line and write to output for _, iInfo := range arrLicenseInfo { licenseInfo = iInfo.(schema.LicenseInfo) lc := licenseInfo.LicenseChoice @@ -368,6 +369,7 @@ func DisplayLicenseListCSV(bom *schema.BOM, writer io.Writer, flags utils.Licens os.Exit(ERROR_VALIDATION) } + // Format each LicenseInfo as a line and write to output for _, iInfo := range arrLicenseInfo { licenseInfo = iInfo.(schema.LicenseInfo) line, err = prepareReportLineData( @@ -415,12 +417,9 @@ func DisplayLicenseListMarkdown(bom *schema.BOM, writer io.Writer, flags utils.L for _, licenseName := range licenseKeys { arrLicenseInfo, _ := bom.LicenseMap.Get(licenseName) + // Format each LicenseInfo as a line and write to output for _, iInfo := range arrLicenseInfo { - // Each row will contain every field of a CDX LicenseChoice object - line = nil licenseInfo = iInfo.(schema.LicenseInfo) - - // Format line and write to output line, err = prepareReportLineData( licenseInfo, LICENSE_LIST_ROW_DATA, diff --git a/cmd/vulnerability.go b/cmd/vulnerability.go index 55e5d11a..bb61b4a4 100644 --- a/cmd/vulnerability.go +++ b/cmd/vulnerability.go @@ -162,7 +162,6 @@ func vulnerabilityCmdImpl(cmd *cobra.Command, args []string) (err error) { } err = ListVulnerabilities(writer, utils.GlobalFlags.PersistentFlags, utils.GlobalFlags.VulnerabilityFlags, whereFilters) - return } @@ -218,20 +217,19 @@ func ListVulnerabilities(writer io.Writer, persistentFlags utils.PersistentComma getLogger().Infof("Outputting listing (`%s` format)...", format) switch format { case FORMAT_TEXT: - DisplayVulnListText(document, writer, flags) + err = DisplayVulnListText(document, writer, flags) case FORMAT_CSV: err = DisplayVulnListCSV(document, writer, flags) case FORMAT_MARKDOWN: err = DisplayVulnListMarkdown(document, writer, flags) case FORMAT_JSON: - DisplayVulnListJson(document, writer, flags) + err = DisplayVulnListJson(document, writer, flags) default: // Default to Text output for anything else (set as flag default) getLogger().Warningf("Listing not supported for `%s` format; defaulting to `%s` format...", format, FORMAT_JSON) - DisplayVulnListText(document, writer, flags) + err = DisplayVulnListText(document, writer, flags) } - return } @@ -413,7 +411,7 @@ func DisplayVulnListMarkdown(bom *schema.BOM, writer io.Writer, flags utils.Vuln } // Output filtered list of vulnerabilities as JSON -func DisplayVulnListJson(bom *schema.BOM, writer io.Writer, flags utils.VulnerabilityCommandFlags) { +func DisplayVulnListJson(bom *schema.BOM, writer io.Writer, flags utils.VulnerabilityCommandFlags) (err error) { getLogger().Enter() defer getLogger().Exit() @@ -431,5 +429,6 @@ func DisplayVulnListJson(bom *schema.BOM, writer io.Writer, flags utils.Vulnerab // Note: JSON data files MUST ends in a newline as this is a POSIX standard // which is already accounted for by the JSON encoder. - utils.WriteAnyAsEncodedJSONInt(writer, vulnList, utils.GlobalFlags.PersistentFlags.GetOutputIndentInt()) + _, err = utils.WriteAnyAsEncodedJSONInt(writer, vulnList, utils.GlobalFlags.PersistentFlags.GetOutputIndentInt()) + return }