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:
parent
2de1f87c10
commit
f239b80ce1
@ -294,6 +294,7 @@ Global Flags:
|
|||||||
-j, --concurrency int Concurrency (default NumCPU) (default 8)
|
-j, --concurrency int Concurrency (default NumCPU) (default 8)
|
||||||
--cpu-profile-path string Path to CPU profile output file
|
--cpu-profile-path string Path to CPU profile output file
|
||||||
--mem-profile-path string Path to memory profile output file
|
--mem-profile-path string Path to memory profile output file
|
||||||
|
-s, --silent disables congrats outputs
|
||||||
-v, --verbose verbose output
|
-v, --verbose verbose output
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -83,6 +83,7 @@ func (e *Executor) needVersionOption() bool {
|
|||||||
|
|
||||||
func initRootFlagSet(fs *pflag.FlagSet, cfg *config.Config, 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.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.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.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)"))
|
fs.IntVarP(&cfg.Run.Concurrency, "concurrency", "j", getDefaultConcurrency(), wh("Concurrency (default NumCPU)"))
|
||||||
|
@ -258,10 +258,10 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
|
|||||||
p = printers.NewJSON()
|
p = printers.NewJSON()
|
||||||
case config.OutFormatColoredLineNumber, config.OutFormatLineNumber:
|
case config.OutFormatColoredLineNumber, config.OutFormatLineNumber:
|
||||||
p = printers.NewText(e.cfg.Output.PrintIssuedLine,
|
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"))
|
e.log.Child("text_printer"))
|
||||||
case config.OutFormatTab:
|
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"))
|
e.log.Child("tab_printer"))
|
||||||
case config.OutFormatCheckstyle:
|
case config.OutFormatCheckstyle:
|
||||||
p = printers.NewCheckstyle()
|
p = printers.NewCheckstyle()
|
||||||
|
@ -92,6 +92,7 @@ func GetDefaultExcludePatternsStrings() []string {
|
|||||||
|
|
||||||
type Run struct {
|
type Run struct {
|
||||||
IsVerbose bool `mapstructure:"verbose"`
|
IsVerbose bool `mapstructure:"verbose"`
|
||||||
|
Silent bool
|
||||||
CPUProfilePath string
|
CPUProfilePath string
|
||||||
MemProfilePath string
|
MemProfilePath string
|
||||||
Concurrency int
|
Concurrency int
|
||||||
|
@ -13,12 +13,14 @@ import (
|
|||||||
|
|
||||||
type Tab struct {
|
type Tab struct {
|
||||||
printLinterName bool
|
printLinterName bool
|
||||||
|
silent bool
|
||||||
log logutils.Log
|
log logutils.Log
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTab(printLinterName bool, log logutils.Log) *Tab {
|
func NewTab(printLinterName bool, silent bool, log logutils.Log) *Tab {
|
||||||
return &Tab{
|
return &Tab{
|
||||||
printLinterName: printLinterName,
|
printLinterName: printLinterName,
|
||||||
|
silent: silent,
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,8 +42,10 @@ func (p *Tab) Print(ctx context.Context, issues <-chan result.Issue) (bool, erro
|
|||||||
if issuesN != 0 {
|
if issuesN != 0 {
|
||||||
p.log.Infof("Found %d issues", issuesN)
|
p.log.Infof("Found %d issues", issuesN)
|
||||||
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
|
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
|
||||||
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
|
if !p.silent {
|
||||||
fmt.Fprintln(logutils.StdOut, outStr)
|
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
|
||||||
|
fmt.Fprintln(logutils.StdOut, outStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := w.Flush(); err != nil {
|
if err := w.Flush(); err != nil {
|
||||||
|
@ -20,16 +20,18 @@ type Text struct {
|
|||||||
printIssuedLine bool
|
printIssuedLine bool
|
||||||
useColors bool
|
useColors bool
|
||||||
printLinterName bool
|
printLinterName bool
|
||||||
|
silent bool
|
||||||
|
|
||||||
cache filesCache
|
cache filesCache
|
||||||
log logutils.Log
|
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{
|
return &Text{
|
||||||
printIssuedLine: printIssuedLine,
|
printIssuedLine: printIssuedLine,
|
||||||
useColors: useColors,
|
useColors: useColors,
|
||||||
printLinterName: printLinterName,
|
printLinterName: printLinterName,
|
||||||
|
silent: silent,
|
||||||
cache: filesCache{},
|
cache: filesCache{},
|
||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
@ -92,8 +94,10 @@ func (p *Text) Print(ctx context.Context, issues <-chan result.Issue) (bool, err
|
|||||||
if issuesN != 0 {
|
if issuesN != 0 {
|
||||||
p.log.Infof("Found %d issues", issuesN)
|
p.log.Infof("Found %d issues", issuesN)
|
||||||
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
|
} else if ctx.Err() == nil { // don't print "congrats" if timeouted
|
||||||
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
|
if !p.silent {
|
||||||
fmt.Fprintln(logutils.StdOut, outStr)
|
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
|
||||||
|
fmt.Fprintln(logutils.StdOut, outStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return issuesN != 0, nil
|
return issuesN != 0, nil
|
||||||
|
@ -33,6 +33,12 @@ func checkNoIssuesRun(t *testing.T, out string, exitCode int) {
|
|||||||
assert.Equal(t, "Congrats! No issues were found.\n", out)
|
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) {
|
func TestCongratsMessageIfNoIssues(t *testing.T) {
|
||||||
out, exitCode := runGolangciLint(t, "../...")
|
out, exitCode := runGolangciLint(t, "../...")
|
||||||
checkNoIssuesRun(t, out, exitCode)
|
checkNoIssuesRun(t, out, exitCode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user