Skip to content

Commit

Permalink
🧹 Respect output option in vuln command (#1154)
Browse files Browse the repository at this point in the history
This also allows json output.

That might help with testing.

Signed-off-by: Christian Zunker <christian@mondoo.com>
  • Loading branch information
czunker authored Mar 7, 2024
1 parent 0475a9d commit 1cf328f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/cnspec/cmd/vuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"encoding/json"
"strings"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand All @@ -24,7 +25,7 @@ import (

func init() {
rootCmd.AddCommand(vulnCmd)
vulnCmd.Flags().StringP("output", "o", "compact", "Set output format: "+reporter.AllFormats())
vulnCmd.Flags().StringP("output", "o", "full", "Set output format: "+reporter.AllFormats())
vulnCmd.Flags().BoolP("json", "j", false, "Run the query and return the object in a JSON structure.")
vulnCmd.Flags().String("platform-id", "", "Select a specific target asset by providing its platform ID.")
vulnCmd.Flags().String("asset-name", "", "User-override for the asset name")
Expand Down Expand Up @@ -176,7 +177,7 @@ var vulnCmdRun = func(cmd *cobra.Command, runtime *providers.Runtime, cliRes *pl

func printVulns(report *mvd.VulnReport, conf *scanConfig, target string) {
// print the output using the specified output format
r := reporter.NewReporter(reporter.Full, false)
r := reporter.NewReporter(reporter.Formats[strings.ToLower(conf.OutputFormat)], false)

logger.DebugDumpJSON("vulnReport", report)
if err := r.PrintVulns(report, target); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions test/cli/testdata/cnspec_vuln.ct
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ cnspec vuln --help
Scans a target for vulnerabilities

0 comments on commit 1cf328f

Please sign in to comment.