diff --git a/internal/lefthook/run.go b/internal/lefthook/run.go index a8995afd..4e0fb2ac 100644 --- a/internal/lefthook/run.go +++ b/internal/lefthook/run.go @@ -76,17 +76,19 @@ func (l *Lefthook) Run(hookName string, args RunArgs, gitArgs []string) error { log.SetLevel(log.WarnLevel) } - newTags := os.Getenv(envOutput) - tags := os.Getenv(envSkipOutput) + outputLogTags := os.Getenv(envOutput) + outputSkipTags := os.Getenv(envSkipOutput) - var logSettings log.SettingsInterface + var logSettings log.Settings - if tags == "" && cfg.SkipOutput == nil { + if outputSkipTags == "" && cfg.SkipOutput == nil { logSettings = log.NewSettings() - logSettings.ApplySettings(newTags, cfg.Output) + logSettings.ApplySettings(outputLogTags, cfg.Output) } else { + log.Warn("skip_output is deprecated, please use output option") + logSettings = log.NewSkipSettings() //nolint:staticcheck //SA1019: for temporary backward compatibility - logSettings.ApplySettings(tags, cfg.SkipOutput) + logSettings.ApplySettings(outputSkipTags, cfg.SkipOutput) } if !logSettings.SkipMeta() { @@ -201,7 +203,7 @@ Run 'lefthook install' manually.`, func printSummary( duration time.Duration, results []run.Result, - logSettings log.SettingsInterface, + logSettings log.Settings, ) { summaryPrint := log.Separate diff --git a/internal/lefthook/run/runner.go b/internal/lefthook/run/runner.go index 64c3417f..5b7c8b48 100644 --- a/internal/lefthook/run/runner.go +++ b/internal/lefthook/run/runner.go @@ -43,7 +43,7 @@ type Options struct { HookName string GitArgs []string ResultChan chan Result - SkipSettings log.SettingsInterface + SkipSettings log.Settings DisableTTY bool Force bool Files []string diff --git a/internal/log/log.go b/internal/log/log.go index 43f25d9a..8da2ec44 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -60,19 +60,6 @@ const ( spinnerText = " waiting" ) -type SettingsInterface interface { - ApplySettings(tags string, skipOutput interface{}) - SkipSuccess() bool - SkipFailure() bool - SkipSummary() bool - SkipMeta() bool - SkipExecution() bool - SkipExecutionOutput() bool - SkipExecutionInfo() bool - SkipSkips() bool - SkipEmptySummary() bool -} - type StyleLogger struct { style lipgloss.Style } diff --git a/internal/log/settings.go b/internal/log/settings.go index 8b9e487c..440c6a60 100644 --- a/internal/log/settings.go +++ b/internal/log/settings.go @@ -17,14 +17,27 @@ const ( enableAll = ^0 // Set all bits as 1 ) -type Settings int16 +type Settings interface { + ApplySettings(tags string, skipOutput interface{}) + SkipSuccess() bool + SkipFailure() bool + SkipSummary() bool + SkipMeta() bool + SkipExecution() bool + SkipExecutionOutput() bool + SkipExecutionInfo() bool + SkipSkips() bool + SkipEmptySummary() bool +} + +type OutputSettings int16 -func NewSettings() SettingsInterface { - var s Settings +func NewSettings() Settings { + var s OutputSettings return &s } -func (s *Settings) ApplySettings(tags string, output interface{}) { +func (s *OutputSettings) ApplySettings(tags string, output interface{}) { if tags == "" && (output == nil || output == "") { s.enableAll(true) return @@ -50,7 +63,7 @@ func (s *Settings) ApplySettings(tags string, output interface{}) { } } -func (s *Settings) applySetting(setting string) { +func (s *OutputSettings) applySetting(setting string) { switch setting { case "meta": *s |= meta @@ -73,7 +86,7 @@ func (s *Settings) applySetting(setting string) { } } -func (s *Settings) enableAll(val bool) { +func (s *OutputSettings) enableAll(val bool) { if val { *s = enableAll // Enable all params } else { @@ -82,43 +95,43 @@ func (s *Settings) enableAll(val bool) { } // Checks the state of params. -func (s Settings) isEnable(option int16) bool { +func (s OutputSettings) isEnable(option int16) bool { return int16(s)&option != 0 } // Using `SkipX` to maintain backward compatibility. -func (s Settings) SkipSuccess() bool { +func (s OutputSettings) SkipSuccess() bool { return !s.isEnable(success) } -func (s Settings) SkipFailure() bool { +func (s OutputSettings) SkipFailure() bool { return !s.isEnable(failure) } -func (s Settings) SkipSummary() bool { +func (s OutputSettings) SkipSummary() bool { return !s.isEnable(summary) } -func (s Settings) SkipMeta() bool { +func (s OutputSettings) SkipMeta() bool { return !s.isEnable(meta) } -func (s Settings) SkipExecution() bool { +func (s OutputSettings) SkipExecution() bool { return !s.isEnable(execution) } -func (s Settings) SkipExecutionOutput() bool { +func (s OutputSettings) SkipExecutionOutput() bool { return !s.isEnable(executionOutput) } -func (s Settings) SkipExecutionInfo() bool { +func (s OutputSettings) SkipExecutionInfo() bool { return !s.isEnable(executionInfo) } -func (s Settings) SkipSkips() bool { +func (s OutputSettings) SkipSkips() bool { return !s.isEnable(skips) } -func (s Settings) SkipEmptySummary() bool { +func (s OutputSettings) SkipEmptySummary() bool { return !s.isEnable(emptySummary) } diff --git a/internal/log/settings_test.go b/internal/log/settings_test.go index bb55a5da..09b70178 100644 --- a/internal/log/settings_test.go +++ b/internal/log/settings_test.go @@ -113,7 +113,7 @@ func TestSetting(t *testing.T) { }, } { //nolint:dupl // In next versions the `skip_settings_test` will be removed t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { - var settings Settings + var settings OutputSettings (&settings).ApplySettings(tt.tags, tt.settings) diff --git a/internal/log/skip_settings.go b/internal/log/skip_settings.go index eec7a4fe..79bc21c3 100644 --- a/internal/log/skip_settings.go +++ b/internal/log/skip_settings.go @@ -21,7 +21,7 @@ const ( type SkipSettings int16 // Deprecated: Use NewSettings instead. -func NewSkipSettings() SettingsInterface { +func NewSkipSettings() Settings { var s SkipSettings return &s }