Skip to content

Commit

Permalink
For human readable output display json output when '--config-only' is…
Browse files Browse the repository at this point in the history
… used
  • Loading branch information
patilpankaj212 committed Dec 11, 2020
1 parent c33ebed commit 12ce5c6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import (
"go.uber.org/zap"
)

const (
humanOutputFormat = "human"
jsonOutputFormat = "json"
)

// Run executes terrascan in CLI mode
func Run(iacType, iacVersion string, cloudType []string,
iacFilePath, iacDirPath, configFile string, policyPath []string,
Expand Down Expand Up @@ -69,9 +74,14 @@ func Run(iacType, iacVersion string, cloudType []string,
outputWriter := NewOutputWriter(useColors)

if configOnly {
// human readable output doesn't support --config-only flag
// if --config-only flag is set, then display json output
if strings.EqualFold(format, humanOutputFormat) {
format = jsonOutputFormat
}
writer.Write(format, results.ResourceConfig, outputWriter)
} else {
if strings.EqualFold(format, "human") {
if strings.EqualFold(format, humanOutputFormat) {
defaultScanResult := result.NewDefaultScanResult(iacType, iacFilePath, iacDirPath, executor.GetTotalPolicyCount(), verbose, *results.Violations.ViolationStore)
writer.Write(format, defaultScanResult, outputWriter)
} else {
Expand Down

0 comments on commit 12ce5c6

Please sign in to comment.