mirror of
https://github.com/mgechev/revive.git
synced 2024-11-30 08:57:07 +02:00
overwrite error status code from config with set_exit_status (#589)
add set_exit_status flag
This commit is contained in:
parent
935acca925
commit
71b31e26ab
@ -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.
|
- `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.
|
- `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/).
|
- `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
|
### Sample Invocations
|
||||||
|
|
||||||
|
27
main.go
27
main.go
@ -36,6 +36,10 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fail(err.Error())
|
fail(err.Error())
|
||||||
}
|
}
|
||||||
|
if setExitStatus {
|
||||||
|
conf.ErrorCode = 1
|
||||||
|
conf.WarningCode = 1
|
||||||
|
}
|
||||||
|
|
||||||
if len(excludePaths) == 0 { // if no excludes were set in the command line
|
if len(excludePaths) == 0 { // if no excludes were set in the command line
|
||||||
excludePaths = conf.Exclude // use those from the configuration
|
excludePaths = conf.Exclude // use those from the configuration
|
||||||
@ -135,11 +139,14 @@ func (i *arrayFlags) Set(value string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var configPath string
|
var (
|
||||||
var excludePaths arrayFlags
|
configPath string
|
||||||
var formatterName string
|
excludePaths arrayFlags
|
||||||
var help bool
|
formatterName string
|
||||||
var versionFlag bool
|
help bool
|
||||||
|
versionFlag bool
|
||||||
|
setExitStatus bool
|
||||||
|
)
|
||||||
|
|
||||||
var originalUsage = flag.Usage
|
var originalUsage = flag.Usage
|
||||||
|
|
||||||
@ -188,10 +195,11 @@ func init() {
|
|||||||
|
|
||||||
// command line help strings
|
// command line help strings
|
||||||
const (
|
const (
|
||||||
configUsage = "path to the configuration TOML file, defaults to $HOME/revive.toml, if present (i.e. -config myconf.toml)"
|
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/...)"
|
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)"
|
formatterUsage = "formatter to be used for the output (i.e. -formatter stylish)"
|
||||||
versionUsage = "get revive version"
|
versionUsage = "get revive version"
|
||||||
|
exitStatusUsage = "set exit status to 1 if any issues are found, overwrites errorCode and warningCode in config"
|
||||||
)
|
)
|
||||||
|
|
||||||
defaultConfigPath := buildDefaultConfigPath()
|
defaultConfigPath := buildDefaultConfigPath()
|
||||||
@ -200,6 +208,7 @@ func init() {
|
|||||||
flag.Var(&excludePaths, "exclude", excludeUsage)
|
flag.Var(&excludePaths, "exclude", excludeUsage)
|
||||||
flag.StringVar(&formatterName, "formatter", "", formatterUsage)
|
flag.StringVar(&formatterName, "formatter", "", formatterUsage)
|
||||||
flag.BoolVar(&versionFlag, "version", false, versionUsage)
|
flag.BoolVar(&versionFlag, "version", false, versionUsage)
|
||||||
|
flag.BoolVar(&setExitStatus, "set_exit_status", false, exitStatusUsage)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Output build info (version, commit, date and builtBy)
|
// Output build info (version, commit, date and builtBy)
|
||||||
|
Loading…
Reference in New Issue
Block a user