Skip to content

Commit

Permalink
feat: add execution_out to skip output settings (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Apr 27, 2023
1 parent 9bc519b commit 7c90e79
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
15 changes: 8 additions & 7 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ min_version: 1.1.3

You can manage the verbosity using the `skip_output` config. You can set whether lefthook should print some parts of its output.

Possible values are `meta,success,failure,summary,execution,skips`.
Possible values are `meta,success,failure,summary,execution,execution_out,skips`.

This config quiets all outputs except for errors.

Expand All @@ -121,12 +121,13 @@ This config quiets all outputs except for errors.
# lefthook.yml
skip_output:
- meta # Skips lefthook version printing
- summary # Skips summary block (successful and failed steps) printing
- success # Skips successful steps printing
- failure # Skips failed steps printing
- execution # Skips printing successfully executed commands and their output (but still prints failed executions)
- skips # Skips "skip" printing (i.e. no files matched)
- meta # Skips lefthook version printing
- summary # Skips summary block (successful and failed steps) printing
- success # Skips successful steps printing
- failure # Skips failed steps printing
- execution # Skips printing successfully executed commands and their output (but still prints failed executions)
- execution_out # Skips printing commands output (but still prints failed commands output)
- skips # Skips "skip" printing (i.e. no files matched)
```

You can also *extend* this list with an environment variable `LEFTHOOK_QUIET`:
Expand Down
2 changes: 1 addition & 1 deletion internal/lefthook/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const (
envEnabled = "LEFTHOOK" // "0", "false"
envSkipOutput = "LEFTHOOK_QUIET" // "meta,success,failure,summary,execution"
envSkipOutput = "LEFTHOOK_QUIET" // "meta,success,failure,summary,execution,execution_out,skips"
envVerbose = "LEFTHOOK_VERBOSE" // keep all output
)

Expand Down
7 changes: 6 additions & 1 deletion internal/lefthook/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,12 @@ func (r *Runner) run(opts ExecuteOptions, follow bool) bool {
return false
}

log.Infof("%s\n%s", execName, out)
if r.SkipSettings.SkipExecutionOutput() {
log.Infof("%s\n", execName)
} else {
log.Infof("%s\n%s", execName, out)
}

if err != nil {
log.Infof("%s", err)
}
Expand Down
13 changes: 10 additions & 3 deletions internal/log/skip_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const (
skipFailure
skipSummary
skipExecution
skipExecutionOutput
skipSkips
)

type SkipSettings int8
type SkipSettings int16

func (s *SkipSettings) ApplySetting(setting string) {
switch setting {
Expand All @@ -25,6 +26,8 @@ func (s *SkipSettings) ApplySetting(setting string) {
*s |= skipSkips
case "execution":
*s |= skipExecution
case "execution_out":
*s |= skipExecutionOutput
}
}

Expand All @@ -48,10 +51,14 @@ func (s SkipSettings) SkipExecution() bool {
return s.doSkip(skipExecution)
}

func (s SkipSettings) SkipExecutionOutput() bool {
return s.doSkip(skipExecutionOutput)
}

func (s SkipSettings) SkipSkips() bool {
return s.doSkip(skipSkips)
}

func (s SkipSettings) doSkip(option int8) bool {
return int8(s)&option != 0
func (s SkipSettings) doSkip(option int16) bool {
return int16(s)&option != 0
}
22 changes: 16 additions & 6 deletions internal/log/skip_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ func TestSkipSetting(t *testing.T) {
},
},
{
settings: []string{"meta", "summary", "success", "failure", "execution"},
settings: []string{"meta", "summary", "success", "failure", "execution", "execution_out", "skips"},
results: map[string]bool{
"meta": true,
"summary": true,
"success": true,
"failure": true,
"execution": true,
"meta": true,
"summary": true,
"success": true,
"failure": true,
"execution": true,
"execution_out": true,
"skips": true,
},
},
} {
Expand Down Expand Up @@ -58,6 +60,14 @@ func TestSkipSetting(t *testing.T) {
if settings.SkipExecution() != tt.results["execution"] {
t.Errorf("expected SkipExecution to be %v", tt.results["execution"])
}

if settings.SkipExecutionOutput() != tt.results["execution_out"] {
t.Errorf("expected SkipExecutionOutput to be %v", tt.results["execution_out"])
}

if settings.SkipSkips() != tt.results["skips"] {
t.Errorf("expected SkipSkips to be %v", tt.results["skip"])
}
})
}
}

0 comments on commit 7c90e79

Please sign in to comment.