Skip to content

Commit

Permalink
add output format option to cli args
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Kanchwala authored and cesar-rodriguez committed Aug 14, 2020
1 parent 759bf66 commit c5ecf5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cmd/terrascan/main.go
Expand Up @@ -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()

Expand All @@ -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)
}
}
5 changes: 3 additions & 2 deletions pkg/cli/run.go
Expand Up @@ -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,
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/writer/writer.go
Expand Up @@ -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
Expand Down

0 comments on commit c5ecf5b

Please sign in to comment.