Skip to content

Commit 430deb7

Browse files
authored
Merge pull request #31 from ytet5uy4/master
Return error code when issue exists
2 parents c19cbb5 + 6c3ff11 commit 430deb7

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Please show `tflint --help`
7272
--aws-secret-key set AWS secret key used in deep check mode.
7373
--aws-region set AWS region used in deep check mode.
7474
-d, --debug enable debug mode.
75+
--error-with-issues return exit status code when issue exists.
7576
```
7677

7778
## Configuration

cli.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
const (
1717
ExitCodeOK int = 0
1818
ExitCodeError int = 1 + iota
19+
ExitCodeIssuesFound
1920
)
2021

2122
// CLI is the command line object
@@ -37,17 +38,18 @@ type TestCLIOptions struct {
3738
// Run invokes the CLI with the given arguments.
3839
func (cli *CLI) Run(args []string) int {
3940
var (
40-
version bool
41-
help bool
42-
debug bool
43-
format string
44-
ignoreModule string
45-
ignoreRule string
46-
configFile string
47-
deepCheck bool
48-
awsAccessKey string
49-
awsSecretKey string
50-
awsRegion string
41+
version bool
42+
help bool
43+
debug bool
44+
format string
45+
ignoreModule string
46+
ignoreRule string
47+
configFile string
48+
deepCheck bool
49+
awsAccessKey string
50+
awsSecretKey string
51+
awsRegion string
52+
errorWithIssues bool
5153
)
5254

5355
// Define option flag parse
@@ -71,6 +73,7 @@ func (cli *CLI) Run(args []string) int {
7173
flags.StringVar(&awsAccessKey, "aws-access-key", "", "AWS access key used in deep check mode.")
7274
flags.StringVar(&awsSecretKey, "aws-secret-key", "", "AWS secret key used in deep check mode.")
7375
flags.StringVar(&awsRegion, "aws-region", "", "AWS region used in deep check mode.")
76+
flags.BoolVar(&errorWithIssues, "error-with-issues", false, "return exit status code when issue exists.")
7477

7578
// Parse commandline flag
7679
if err := flags.Parse(args[1:]); err != nil {
@@ -148,6 +151,10 @@ func (cli *CLI) Run(args []string) int {
148151

149152
p := printer.NewPrinter(cli.outStream, cli.errStream)
150153
p.Print(issues, format)
154+
155+
if errorWithIssues && len(issues) > 0 {
156+
return ExitCodeIssuesFound
157+
}
151158
}
152159

153160
return ExitCodeOK

help.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Available options:
1616
--aws-secret-key set AWS secret key used in deep check mode.
1717
--aws-region set AWS region used in deep check mode.
1818
-d, --debug enable debug mode.
19+
--error-with-issues return exit status code when issue exists.
1920
2021
Support aruguments:
2122
TFLint scans all configuration file of Terraform in current directory by default.

0 commit comments

Comments
 (0)