disable the congrats message

There is now an extra switch '-s' to disable the congrats message when
there are no issues detected

Fixes: #110
This commit is contained in:
Henrik Johansson 2018-06-15 14:34:54 +02:00 committed by Isaev Denis
parent 2de1f87c10
commit f239b80ce1
7 changed files with 25 additions and 8 deletions

View File

@ -294,6 +294,7 @@ Global Flags:
-j, --concurrency int Concurrency (default NumCPU) (default 8)
--cpu-profile-path string Path to CPU profile output file
--mem-profile-path string Path to memory profile output file
-s, --silent disables congrats outputs
-v, --verbose verbose output
```

View File

@ -83,6 +83,7 @@ func (e *Executor) needVersionOption() bool {
func initRootFlagSet(fs *pflag.FlagSet, cfg *config.Config, needVersionOption bool) {
fs.BoolVarP(&cfg.Run.IsVerbose, "verbose", "v", false, wh("verbose output"))
fs.BoolVarP(&cfg.Run.Silent, "silent", "s", false, wh("disables congrats outputs"))
fs.StringVar(&cfg.Run.CPUProfilePath, "cpu-profile-path", "", wh("Path to CPU profile output file"))
fs.StringVar(&cfg.Run.MemProfilePath, "mem-profile-path", "", wh("Path to memory profile output file"))
fs.IntVarP(&cfg.Run.Concurrency, "concurrency", "j", getDefaultConcurrency(), wh("Concurrency (default NumCPU)"))

View File

@ -258,10 +258,10 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
p = printers.NewJSON()
case config.OutFormatColoredLineNumber, config.OutFormatLineNumber:
p = printers.NewText(e.cfg.Output.PrintIssuedLine,
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName,
format == config.OutFormatColoredLineNumber, e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
e.log.Child("text_printer"))
case config.OutFormatTab:
p = printers.NewTab(e.cfg.Output.PrintLinterName,
p = printers.NewTab(e.cfg.Output.PrintLinterName, e.cfg.Run.Silent,
e.log.Child("tab_printer"))
case config.OutFormatCheckstyle:
p = printers.NewCheckstyle()

View File

@ -92,6 +92,7 @@ func GetDefaultExcludePatternsStrings() []string {
type Run struct {
IsVerbose bool `mapstructure:"verbose"`
Silent bool
CPUProfilePath string
MemProfilePath string
Concurrency int

View File

@ -13,12 +13,14 @@ import (
type Tab struct {
printLinterName bool
silent bool
log logutils.Log
}
func NewTab(printLinterName bool, log logutils.Log) *Tab {
func NewTab(printLinterName bool, silent bool, log logutils.Log) *Tab {
return &Tab{
printLinterName: printLinterName,
silent: silent,
log: log,
}
}
@ -40,8 +42,10 @@ func (p *Tab) Print(ctx context.Context, issues <-chan result.Issue) (bool, erro
if issuesN != 0 {
p.log.Infof("Found %d issues", issuesN)
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
fmt.Fprintln(logutils.StdOut, outStr)
if !p.silent {
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
fmt.Fprintln(logutils.StdOut, outStr)
}
}
if err := w.Flush(); err != nil {

View File

@ -20,16 +20,18 @@ type Text struct {
printIssuedLine bool
useColors bool
printLinterName bool
silent bool
cache filesCache
log logutils.Log
}
func NewText(printIssuedLine, useColors, printLinterName bool, log logutils.Log) *Text {
func NewText(printIssuedLine, useColors, printLinterName bool, silent bool, log logutils.Log) *Text {
return &Text{
printIssuedLine: printIssuedLine,
useColors: useColors,
printLinterName: printLinterName,
silent: silent,
cache: filesCache{},
log: log,
}
@ -92,8 +94,10 @@ func (p *Text) Print(ctx context.Context, issues <-chan result.Issue) (bool, err
if issuesN != 0 {
p.log.Infof("Found %d issues", issuesN)
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
fmt.Fprintln(logutils.StdOut, outStr)
if !p.silent {
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
fmt.Fprintln(logutils.StdOut, outStr)
}
}
return issuesN != 0, nil

View File

@ -33,6 +33,12 @@ func checkNoIssuesRun(t *testing.T, out string, exitCode int) {
assert.Equal(t, "Congrats! No issues were found.\n", out)
}
func TestCongratsMessageGoneIfSilent(t *testing.T) {
out, exitCode := runGolangciLint(t, "../...", "-s")
assert.Equal(t, exitcodes.Success, exitCode)
assert.Equal(t, "", out)
}
func TestCongratsMessageIfNoIssues(t *testing.T) {
out, exitCode := runGolangciLint(t, "../...")
checkNoIssuesRun(t, out, exitCode)