Skip to content

Commit 7883b89

Browse files
authored
add show flag to show values for resp features (#444)
1 parent 333a9f1 commit 7883b89

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

cmd/list.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type userListCmd struct {
4040
json bool
4141
detailed bool
4242
color bool
43+
show bool
4344

4445
// Debug control
4546
debug bool
@@ -67,11 +68,13 @@ var listCmd = &cobra.Command{
6768
# Component features:
6869
[comp_with_name, comp_with_version, comp_with_supplier, comp_with_uniq_ids, comp_valid_licenses, comp_with_any_vuln_lookup_id,
6970
comp_with_deprecated_licenses, comp_with_multi_vuln_lookup_id, comp_with_primary_purpose, comp_with_restrictive_licenses,
70-
comp_with_checksums, comp_with_licenses]
71+
comp_with_checksums, comp_with_licenses, comp_with_checksums_sha256, comp_with_source_code_uri, comp_with_source_code_hash,
72+
comp_with_executable_uri, comp_with_associated_license, comp_with_concluded_license, comp_with_declared_license]
7173
7274
# SBOM features:
7375
[sbom_creation_timestamp, sbom_authors, sbom_with_creator_and_version, sbom_with_primary_component, sbom_dependencies,
74-
sbom_sharable, sbom_parsable, sbom_spec, sbom_spec_file_format, sbom_spec_version]
76+
sbom_sharable, sbom_parsable, sbom_spec, sbom_file_format, sbom_spec_version, spec_with_version_compliant, sbom_with_uri,
77+
sbom_with_vuln, sbom_build_process]
7578
`,
7679

7780
Args: func(_ *cobra.Command, args []string) error {
@@ -130,6 +133,9 @@ func parseListParams(cmd *cobra.Command, args []string) *userListCmd {
130133
color, _ := cmd.Flags().GetBool("color")
131134
uCmd.color = color
132135

136+
show, _ := cmd.Flags().GetBool("show")
137+
uCmd.show = show
138+
133139
// Debug control
134140
debug, _ := cmd.Flags().GetBool("debug")
135141
uCmd.debug = debug
@@ -147,6 +153,7 @@ func fromListToEngineParams(uCmd *userListCmd) *engine.Params {
147153
Detailed: uCmd.detailed,
148154
Color: uCmd.color,
149155
Debug: uCmd.debug,
156+
Show: uCmd.show,
150157
}
151158
}
152159

@@ -166,6 +173,7 @@ func init() {
166173
listCmd.Flags().BoolP("json", "j", false, "Results in JSON")
167174
listCmd.Flags().BoolP("detailed", "d", true, "Results in table format, default")
168175
listCmd.Flags().BoolP("color", "l", false, "Output in color")
176+
listCmd.Flags().BoolP("show", "s", false, "Show values of features, (default: false)")
169177

170178
// Debug Control
171179
listCmd.Flags().BoolP("debug", "D", false, "Enable debug logging")

pkg/engine/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func parseListParams(ep *Params) *list.Params {
3131
Color: ep.Color,
3232
Missing: ep.Missing,
3333
Debug: ep.Debug,
34+
Show: ep.Show,
3435
}
3536
}
3637

pkg/engine/score.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Params struct {
5252
Missing bool
5353

5454
Debug bool
55+
Show bool
5556

5657
ConfigPath string
5758

pkg/list/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ func parseSBOMDocument(ctx context.Context, filePath string) (sbom.Document, err
146146
// processFeatureForSBOM processes a single feature for an SBOM document and returns a ListResult
147147
func processFeatureForSBOM(ctx context.Context, ep *Params, doc sbom.Document, filePath, feature string) (*Result, error) {
148148
log := logger.FromContext(ctx)
149+
log.Debug("list.processFeatureForSBOM()")
150+
log.Debug("processing feature: ", feature)
149151
feature = strings.TrimSpace(feature)
150152

151153
// Validate the feature
@@ -175,6 +177,7 @@ func processFeatureForSBOM(ctx context.Context, ep *Params, doc sbom.Document, f
175177
// processComponentFeature processes a component-based feature for an SBOM document
176178
func processComponentFeature(ctx context.Context, ep *Params, doc sbom.Document, result *Result) (*Result, error) {
177179
log := logger.FromContext(ctx)
180+
log.Debug("processing component feature: ", result.Feature)
178181
result.Components = []ComponentResult{}
179182
var totalComponents int
180183

@@ -243,8 +246,9 @@ func generateReport(ctx context.Context, results []*Result, ep *Params) error {
243246
reportFormat = "json"
244247
}
245248
coloredOutput := ep.Color
249+
show := ep.Show
246250

247-
lnr := NewListReport(ctx, results, WithFormat(strings.ToLower(reportFormat)), WithColor(coloredOutput))
251+
lnr := NewListReport(ctx, results, WithFormat(strings.ToLower(reportFormat)), WithColor(coloredOutput), WithValues(show))
248252
lnr.Report()
249253
return nil
250254
}

pkg/list/report.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,19 @@ func WithColor(c bool) OptionList {
5454
}
5555
}
5656

57+
func WithValues(s bool) OptionList {
58+
return func(r *Report) {
59+
r.Show = s
60+
}
61+
}
62+
5763
// listReport holds the state for reporting the list command results
5864
type Report struct {
5965
Ctx context.Context
6066
Results []*Result
6167
Format string
6268
Color bool
69+
Show bool // show values for corresponding features
6370
}
6471

6572
// Report renders the list command results in the specified format
@@ -97,13 +104,21 @@ func (r *Report) detailedReport() {
97104
if result.Missing {
98105
presence = "missing"
99106
}
107+
show := r.Show
108+
fmt.Println()
100109
fmt.Printf("File: %s\tFeature: %s (%s)\n", result.FilePath, result.Feature, presence)
101110

102111
// Initialize tablewriter
103112
table := tablewriter.NewWriter(os.Stdout)
104113
if strings.HasPrefix(result.Feature, "comp_") {
114+
115+
if show {
116+
table.SetHeader([]string{"Feature", "Component Name", "Version", "Value"})
117+
} else {
118+
table.SetHeader([]string{"Feature", "Component Name", "Version"})
119+
}
120+
105121
// Component-based feature
106-
table.SetHeader([]string{"Feature", "Component Name", "Version"})
107122
featureCol := fmt.Sprintf("%s (%d/%d)", result.Feature, len(result.Components), result.TotalComponents)
108123
if len(result.Components) == 0 {
109124
// No components to display
@@ -119,29 +134,38 @@ func (r *Report) detailedReport() {
119134
versionCol := color.New(color.FgHiGreen).Sprint(comp.Version)
120135
table.Append([]string{featureCol1, nameCol, versionCol})
121136
}
122-
table.Append([]string{featureCol, comp.Name, comp.Version})
123-
137+
if show {
138+
table.Append([]string{featureCol, comp.Name, comp.Version, comp.Values})
139+
} else {
140+
table.Append([]string{featureCol, comp.Name, comp.Version})
141+
}
124142
}
125143

126144
} else {
127145
// SBOM-based feature
128146
featureCol := fmt.Sprintf("%s (%s)", result.Feature, presence)
147+
table.SetHeader([]string{"Feature", "SBOM Feature", "Value"})
148+
129149
if r.Color {
130150
featureCol1 := color.New(color.FgHiCyan).Sprint(featureCol)
131151
propertyCol := color.New(color.FgHiBlue).Sprint(result.DocumentProperty.Key)
132152
valueCol := color.New(color.FgHiBlue).Sprint(result.DocumentProperty.Value)
133153
table.Append([]string{featureCol1, propertyCol, valueCol})
134154
} else {
135155
if result.DocumentProperty.Present {
156+
if result.DocumentProperty.Value == "" {
157+
result.DocumentProperty.Value = "N/A"
158+
}
136159
table.Append([]string{featureCol, result.DocumentProperty.Key, result.DocumentProperty.Value})
137160
} else {
138-
table.Append([]string{featureCol, result.DocumentProperty.Key, "N/A"})
161+
if result.DocumentProperty.Value == "" {
162+
result.DocumentProperty.Value = "N/A"
163+
}
164+
table.Append([]string{featureCol, result.DocumentProperty.Key, result.DocumentProperty.Value})
139165
}
140166
}
141167
}
142168

143-
// Configure table settings
144-
table.SetHeader([]string{"Feature", "Key/Component Name", "Value/Version"})
145169
table.SetRowLine(true)
146170
table.SetColWidth(50)
147171
table.SetAutoMergeCellsByColumnIndex([]int{0})

pkg/list/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Params struct {
4747
Basic bool
4848
Detailed bool
4949
Color bool
50+
Show bool
5051

5152
Missing bool
5253

0 commit comments

Comments
 (0)