Skip to content

Commit

Permalink
fix: correctly parse config options (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Dec 18, 2024
1 parent 1e38d75 commit f2704a3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Command struct {
Priority int `json:"priority,omitempty" mapstructure:"priority" toml:"priority,omitempty" yaml:",omitempty"`
FailText string `json:"fail_text,omitempty" koanf:"fail_text" mapstructure:"fail_text" toml:"fail_text,omitempty" yaml:"fail_text,omitempty"`
Interactive bool `json:"interactive,omitempty" mapstructure:"interactive" toml:"interactive,omitempty" yaml:",omitempty"`
UseStdin bool `json:"use_stdin,omitempty" mapstructure:"use_stdin" toml:"use_stdin,omitempty" yaml:",omitempty"`
UseStdin bool `json:"use_stdin,omitempty" koanf:"use_stdin" mapstructure:"use_stdin" toml:"use_stdin,omitempty" yaml:"use_stdin,omitempty"`
StageFixed bool `json:"stage_fixed,omitempty" koanf:"stage_fixed" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"`
}

Expand Down
6 changes: 3 additions & 3 deletions internal/config/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ type Script struct {
Env map[string]string `json:"env,omitempty" mapstructure:"env" toml:"env,omitempty" yaml:",omitempty"`
Priority int `json:"priority,omitempty" mapstructure:"priority" toml:"priority,omitempty" yaml:",omitempty"`

FailText string `json:"fail_text,omitempty" mapstructure:"fail_text" toml:"fail_text,omitempty" yaml:"fail_text,omitempty"`
FailText string `json:"fail_text,omitempty" koanf:"fail_text" mapstructure:"fail_text" toml:"fail_text,omitempty" yaml:"fail_text,omitempty"`
Interactive bool `json:"interactive,omitempty" mapstructure:"interactive" toml:"interactive,omitempty" yaml:",omitempty"`
UseStdin bool `json:"use_stdin,omitempty" mapstructure:"use_stdin" toml:"use_stdin,omitempty" yaml:",omitempty"`
StageFixed bool `json:"stage_fixed,omitempty" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"`
UseStdin bool `json:"use_stdin,omitempty" koanf:"use_stdin" mapstructure:"use_stdin" toml:"use_stdin,omitempty" yaml:"use_stdin,omitempty"`
StageFixed bool `json:"stage_fixed,omitempty" koanf:"stage_fixed" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"`
}

func (s Script) DoSkip(state func() git.State) bool {
Expand Down
33 changes: 33 additions & 0 deletions testdata/dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pre-commit:
skip: merge
glob: "*.js"
run: yarn test
scripts:
"my-script.sh":
runner: bash
use_stdin: true
stage_fixed: true
env:
FOO: bar
-- lefthook-dumped.yml --
colors:
cyan: 14
Expand All @@ -54,6 +61,13 @@ pre-commit:
run: yarn test
skip: merge
glob: '*.js'
scripts:
my-script.sh:
runner: bash
env:
FOO: bar
use_stdin: true
stage_fixed: true
follow: true
-- lefthook-dumped.json --
{
Expand Down Expand Up @@ -83,6 +97,16 @@ pre-commit:
"glob": "*.js"
}
},
"scripts": {
"my-script.sh": {
"runner": "bash",
"env": {
"FOO": "bar"
},
"use_stdin": true,
"stage_fixed": true
}
},
"follow": true
}
}
Expand All @@ -107,3 +131,12 @@ interactive = true
run = 'yarn test'
skip = 'merge'
glob = '*.js'

[pre-commit.scripts]
[pre-commit.scripts.'my-script.sh']
runner = 'bash'
use_stdin = true
stage_fixed = true

[pre-commit.scripts.'my-script.sh'.env]
FOO = 'bar'

0 comments on commit f2704a3

Please sign in to comment.