Skip to content

Commit

Permalink
added skip_output: true option that silences everything
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklyarov committed Jan 4, 2024
1 parent 10f5ad4 commit 3145c4f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Config struct {
SourceDir string `mapstructure:"source_dir"`
SourceDirLocal string `mapstructure:"source_dir_local"`
Rc string `mapstructure:"rc,omitempty"`
SkipOutput []string `mapstructure:"skip_output,omitempty"`
SkipOutput interface{} `mapstructure:"skip_output,omitempty"`
Extends []string `mapstructure:"extends,omitempty"`
NoTTY bool `mapstructure:"no_tty,omitempty"`
AssertLefthookInstalled bool `mapstructure:"assert_lefthook_installed,omitempty"`
Expand Down
10 changes: 3 additions & 7 deletions internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os/signal"
"path/filepath"
"slices"
"strings"
"time"

"github.com/evilmartians/lefthook/internal/config"
Expand Down Expand Up @@ -61,6 +60,7 @@ func (l *Lefthook) Run(hookName string, args RunArgs, gitArgs []string) error {

return err
}

if err = cfg.Validate(); err != nil {
return err
}
Expand All @@ -73,14 +73,10 @@ func (l *Lefthook) Run(hookName string, args RunArgs, gitArgs []string) error {
log.SetLevel(log.WarnLevel)
}

if tags := os.Getenv(envSkipOutput); tags != "" {
cfg.SkipOutput = append(cfg.SkipOutput, strings.Split(tags, ",")...)
}
tags := os.Getenv(envSkipOutput)

var logSettings log.SkipSettings
for _, skipOption := range cfg.SkipOutput {
(&logSettings).ApplySetting(skipOption)
}
(&logSettings).ApplySkipSettings(tags, cfg.SkipOutput)

if !logSettings.SkipMeta() {
log.Box(
Expand Down
26 changes: 26 additions & 0 deletions internal/log/skip_settings.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package log

import "strings"

const (
skipMeta = 1 << iota
skipSuccess
Expand All @@ -10,6 +12,7 @@ const (
skipExecutionOutput
skipExecutionInfo
skipEmptySummary
skipAll = (1 << iota) - 1
)

type SkipSettings int16
Expand Down Expand Up @@ -37,6 +40,29 @@ func (s *SkipSettings) ApplySetting(setting string) {
}
}

func (s *SkipSettings) ApplySkipSettings(tags string, skipOutput interface{}) {
switch typedSkipOutput := skipOutput.(type) {
case bool:
s.SkipAll(typedSkipOutput)
case []string:
if tags != "" {
typedSkipOutput = append(typedSkipOutput, strings.Split(tags, ",")...)
}
for _, skipOption := range typedSkipOutput {
s.ApplySetting(skipOption)
}
}
}

func (s *SkipSettings) SkipAll(val bool) {
if val == true {

Check failure on line 58 in internal/log/skip_settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1002: should omit comparison to bool constant, can be simplified to `val` (gosimple)
*s = skipAll &^ skipFailure
} else {
*s = 0
}
return

Check failure on line 63 in internal/log/skip_settings.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1023: redundant `return` statement (gosimple)
}

func (s SkipSettings) SkipSuccess() bool {
return s.doSkip(skipSuccess)
}
Expand Down

0 comments on commit 3145c4f

Please sign in to comment.