From 71b31e26ab2e4d85e9b3afe7feee67106ebf353e Mon Sep 17 00:00:00 2001 From: Jan Steinke Date: Tue, 12 Oct 2021 22:10:35 +0200 Subject: [PATCH] overwrite error status code from config with set_exit_status (#589) add set_exit_status flag --- README.md | 1 + main.go | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bee6f09..5064480 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index 0f7a8be..394e811 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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 @@ -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() @@ -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)