Skip to content

Commit

Permalink
overwrite error status code from config with set_exit_status (#589)
Browse files Browse the repository at this point in the history
add set_exit_status flag
  • Loading branch information
Jan Steinke authored Oct 12, 2021
1 parent 935acca commit 71b31e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Please notice that if no particular configuration is provided, `revive` will beh
- `friendly` - outputs the failures when found. Shows summary of all the failures.
- `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.
- `checkstyle` - outputs the failures in XML format compatible with that of Java's [Checkstyle](https://checkstyle.org/).
- `-set_exit_status` - set exit status to 1 if any issues are found, overwrites errorCode and warningCode in config.

### Sample Invocations

Expand Down
27 changes: 18 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func main() {
if err != nil {
fail(err.Error())
}
if setExitStatus {
conf.ErrorCode = 1
conf.WarningCode = 1
}

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

var configPath string
var excludePaths arrayFlags
var formatterName string
var help bool
var versionFlag bool
var (
configPath string
excludePaths arrayFlags
formatterName string
help bool
versionFlag bool
setExitStatus bool
)

var originalUsage = flag.Usage

Expand Down Expand Up @@ -188,10 +195,11 @@ func init() {

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

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

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

0 comments on commit 71b31e2

Please sign in to comment.