Skip to content

Commit 71b31e2

Browse files
author
Jan Steinke
authored
overwrite error status code from config with set_exit_status (#589)
add set_exit_status flag
1 parent 935acca commit 71b31e2

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Please notice that if no particular configuration is provided, `revive` will beh
191191
- `friendly` - outputs the failures when found. Shows summary of all the failures.
192192
- `stylish` - formats the failures in a table. Keep in mind that it doesn't stream the output so it might be perceived as slower compared to others.
193193
- `checkstyle` - outputs the failures in XML format compatible with that of Java's [Checkstyle](https://checkstyle.org/).
194+
- `-set_exit_status` - set exit status to 1 if any issues are found, overwrites errorCode and warningCode in config.
194195

195196
### Sample Invocations
196197

main.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func main() {
3636
if err != nil {
3737
fail(err.Error())
3838
}
39+
if setExitStatus {
40+
conf.ErrorCode = 1
41+
conf.WarningCode = 1
42+
}
3943

4044
if len(excludePaths) == 0 { // if no excludes were set in the command line
4145
excludePaths = conf.Exclude // use those from the configuration
@@ -135,11 +139,14 @@ func (i *arrayFlags) Set(value string) error {
135139
return nil
136140
}
137141

138-
var configPath string
139-
var excludePaths arrayFlags
140-
var formatterName string
141-
var help bool
142-
var versionFlag bool
142+
var (
143+
configPath string
144+
excludePaths arrayFlags
145+
formatterName string
146+
help bool
147+
versionFlag bool
148+
setExitStatus bool
149+
)
143150

144151
var originalUsage = flag.Usage
145152

@@ -188,10 +195,11 @@ func init() {
188195

189196
// command line help strings
190197
const (
191-
configUsage = "path to the configuration TOML file, defaults to $HOME/revive.toml, if present (i.e. -config myconf.toml)"
192-
excludeUsage = "list of globs which specify files to be excluded (i.e. -exclude foo/...)"
193-
formatterUsage = "formatter to be used for the output (i.e. -formatter stylish)"
194-
versionUsage = "get revive version"
198+
configUsage = "path to the configuration TOML file, defaults to $HOME/revive.toml, if present (i.e. -config myconf.toml)"
199+
excludeUsage = "list of globs which specify files to be excluded (i.e. -exclude foo/...)"
200+
formatterUsage = "formatter to be used for the output (i.e. -formatter stylish)"
201+
versionUsage = "get revive version"
202+
exitStatusUsage = "set exit status to 1 if any issues are found, overwrites errorCode and warningCode in config"
195203
)
196204

197205
defaultConfigPath := buildDefaultConfigPath()
@@ -200,6 +208,7 @@ func init() {
200208
flag.Var(&excludePaths, "exclude", excludeUsage)
201209
flag.StringVar(&formatterName, "formatter", "", formatterUsage)
202210
flag.BoolVar(&versionFlag, "version", false, versionUsage)
211+
flag.BoolVar(&setExitStatus, "set_exit_status", false, exitStatusUsage)
203212
flag.Parse()
204213

205214
// Output build info (version, commit, date and builtBy)

0 commit comments

Comments
 (0)