Skip to content

Commit b645cf7

Browse files
committed
Control setup logs via setting
1 parent 9f92951 commit b645cf7

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

.lefthook.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
assert_lefthook_installed: true
22
skip_lfs: true
33

4+
output:
5+
- meta
6+
- summary
7+
- jobs
8+
49
pre-commit:
510
parallel: true
611
setup:

internal/log/settings.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,10 @@ const (
1414
executionOutput
1515
executionInfo
1616
emptySummary
17+
setup
1718
)
1819

19-
const (
20-
disableAll = 0
21-
skipMeta = (1 << iota)
22-
skipSuccess
23-
skipFailure
24-
skipSummary
25-
skipSkips
26-
skipExecution
27-
skipExecutionOutput
28-
skipExecutionInfo
29-
skipEmptySummary
30-
)
20+
const disableAll = 0
3121

3222
type LogSettings struct {
3323
bitmap int16
@@ -95,14 +85,16 @@ func (s *LogSettings) enable(setting string) {
9585
s.bitmap |= summary | success | failure
9686
case "skips":
9787
s.bitmap |= skips
98-
case "execution":
88+
case "execution", "jobs":
9989
s.bitmap |= execution | executionOutput | executionInfo
100-
case "execution_out":
90+
case "execution_out", "jobs_out":
10191
s.bitmap |= executionOutput | execution
102-
case "execution_info":
92+
case "execution_info", "jobs_info":
10393
s.bitmap |= executionInfo | execution
10494
case "empty_summary":
10595
s.bitmap |= emptySummary
96+
case "setup":
97+
s.bitmap |= setup
10698
}
10799
}
108100

@@ -154,3 +146,7 @@ func (s LogSettings) LogSkips() bool {
154146
func (s LogSettings) LogEmptySummary() bool {
155147
return s.isEnable(emptySummary)
156148
}
149+
150+
func (s LogSettings) LogSetup() bool {
151+
return s.isEnable(setup)
152+
}

internal/log/setup.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
package log
22

3-
import "github.com/charmbracelet/lipgloss"
3+
import (
4+
"io"
5+
"os"
46

5-
func LogSetup() {
6-
Styled().
7-
WithLeftBorder(lipgloss.ThickBorder(), ColorYellow).
8-
WithPadding(execLogPadding).
9-
Info(Yellow("setup ❯ "))
7+
"github.com/charmbracelet/lipgloss"
8+
)
9+
10+
func LogSetup(r io.Reader) {
11+
go func() {
12+
if !Settings.LogSetup() {
13+
_, _ = io.Copy(io.Discard, r)
14+
return
15+
}
16+
17+
Styled().
18+
WithLeftBorder(lipgloss.ThickBorder(), ColorYellow).
19+
WithPadding(execLogPadding).
20+
Info(Yellow("setup ❯ "))
21+
22+
_, _ = io.Copy(os.Stdout, r)
23+
}()
1024
}

internal/run/controller/setup.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package controller
22

33
import (
44
"context"
5-
"os"
5+
"io"
66

77
"github.com/evilmartians/lefthook/v2/internal/config"
88
"github.com/evilmartians/lefthook/v2/internal/log"
@@ -37,7 +37,11 @@ func (c *Controller) setup(
3737
commands = append(commands, rawCommands...)
3838
}
3939

40-
log.LogSetup()
40+
r, w := io.Pipe()
41+
log.LogSetup(r)
4142

42-
return c.executor.Execute(ctx, exec.Options{Commands: commands}, system.NullReader, os.Stdout)
43+
err := c.executor.Execute(ctx, exec.Options{Commands: commands}, system.NullReader, w)
44+
_ = w.Close()
45+
46+
return err
4347
}

0 commit comments

Comments
 (0)