From 4294d78c1706c527968e5a1790868c7c0478f5d4 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Tue, 14 Nov 2023 10:52:59 +0300 Subject: [PATCH] chore: skip summary separator if nothing is printed --- internal/lefthook/lefthook.go | 9 +++++---- internal/lefthook/run.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/lefthook/lefthook.go b/internal/lefthook/lefthook.go index 465a1028..a4bbd9a8 100644 --- a/internal/lefthook/lefthook.go +++ b/internal/lefthook/lefthook.go @@ -15,8 +15,9 @@ import ( ) const ( - hookFileMode = 0o755 - envVerbose = "LEFTHOOK_VERBOSE" // keep all output + hookFileMode = 0o755 + envVerbose = "LEFTHOOK_VERBOSE" // keep all output + oldHookPostfix = ".old" ) var lefthookContentRegexp = regexp.MustCompile("LEFTHOOK") @@ -94,7 +95,7 @@ func (l *Lefthook) cleanHook(hook string, force bool) error { } // Check if .old file already exists before renaming. - exists, err = afero.Exists(l.Fs, hookPath+".old") + exists, err = afero.Exists(l.Fs, hookPath+oldHookPostfix) if err != nil { return err } @@ -107,7 +108,7 @@ func (l *Lefthook) cleanHook(hook string, force bool) error { } } - err = l.Fs.Rename(hookPath, hookPath+".old") + err = l.Fs.Rename(hookPath, hookPath+oldHookPostfix) if err != nil { return err } diff --git a/internal/lefthook/run.go b/internal/lefthook/run.go index 3d9266ea..a51ae4b4 100644 --- a/internal/lefthook/run.go +++ b/internal/lefthook/run.go @@ -181,9 +181,15 @@ func printSummary( results []run.Result, logSettings log.SkipSettings, ) { + summaryPrint := log.Separate + + if logSettings.SkipExecution() || (logSettings.SkipExecutionInfo() && logSettings.SkipExecutionOutput()) { + summaryPrint = func(s string) { log.Info(s) } + } + if len(results) == 0 { if !logSettings.SkipEmptySummary() { - log.Separate( + summaryPrint( fmt.Sprintf( "%s %s %s", log.Cyan("summary:"), @@ -195,7 +201,7 @@ func printSummary( return } - log.Separate( + summaryPrint( log.Cyan("summary: ") + log.Gray(fmt.Sprintf("(done in %.2f seconds)", duration.Seconds())), )