diff --git a/cmd/terrascan/main.go b/cmd/terrascan/main.go index 453c93961..db116a4ff 100644 --- a/cmd/terrascan/main.go +++ b/cmd/terrascan/main.go @@ -49,6 +49,9 @@ func main() { // config file configFile = flag.String("config", "", "config file path") + + // output type + output = flag.String("output", "yaml", "output format (json, xml, yaml)") ) flag.Parse() @@ -65,6 +68,6 @@ func main() { } else { logging.Init(*logType, *logLevel) zap.S().Debug("running terrascan in cli mode") - cli.Run(*iacType, *iacVersion, *cloudType, *iacFilePath, *iacDirPath, *configFile, *policyPath) + cli.Run(*iacType, *iacVersion, *cloudType, *iacFilePath, *iacDirPath, *configFile, *policyPath, *output) } } diff --git a/pkg/cli/run.go b/pkg/cli/run.go index 963a7c22e..3e66cdf68 100644 --- a/pkg/cli/run.go +++ b/pkg/cli/run.go @@ -24,7 +24,8 @@ import ( ) // Run executes terrascan in CLI mode -func Run(iacType, iacVersion, cloudType, iacFilePath, iacDirPath, configFile, policyPath string) { +func Run(iacType, iacVersion, cloudType, iacFilePath, iacDirPath, configFile, + policyPath, format string) { // create a new runtime executor for processing IaC executor, err := runtime.NewExecutor(iacType, iacVersion, cloudType, iacFilePath, @@ -38,5 +39,5 @@ func Run(iacType, iacVersion, cloudType, iacFilePath, iacDirPath, configFile, po if err != nil { return } - writer.Write("yaml", violations, os.Stdout) + writer.Write(format, violations, os.Stdout) } diff --git a/pkg/writer/writer.go b/pkg/writer/writer.go index 97bc799f8..a4ef7f964 100644 --- a/pkg/writer/writer.go +++ b/pkg/writer/writer.go @@ -28,9 +28,9 @@ var ( ) // Write method writes in the given format using the respective writer func -func Write(format supportedFormat, data interface{}, writer io.Writer) error { +func Write(format string, data interface{}, writer io.Writer) error { - writerFunc, present := writerMap[format] + writerFunc, present := writerMap[supportedFormat(format)] if !present { zap.S().Error("output format '%s' not supported", format) return errNotSupported