-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/evilmartians/lefthook/internal/lefthook" | ||
) | ||
|
||
func newDumpCmd(opts *lefthook.Options) *cobra.Command { | ||
dumpCmd := cobra.Command{ | ||
Use: "dump", | ||
Short: "Prints config merged from all extensions", | ||
Example: "lefthook dump", | ||
Run: func(cmd *cobra.Command, hooks []string) { | ||
lefthook.Dump(opts) | ||
}, | ||
} | ||
|
||
return &dumpCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/evilmartians/lefthook/internal/version" | ||
) | ||
|
||
const dumpIndent = 2 | ||
|
||
type Config struct { | ||
Colors bool `mapstructure:"colors"` | ||
Extends []string `mapstructure:"extends"` | ||
Remote Remote `mapstructure:"remote"` | ||
MinVersion string `mapstructure:"min_version"` | ||
SkipOutput []string `mapstructure:"skip_output"` | ||
SourceDir string `mapstructure:"source_dir"` | ||
SourceDirLocal string `mapstructure:"source_dir_local"` | ||
Rc string `mapstructure:"rc"` | ||
NoTTY bool `mapstructure:"no_tty"` | ||
Extends []string `mapstructure:"extends" yaml:",omitempty"` | ||
Remote Remote `mapstructure:"remote" yaml:",omitempty"` | ||
MinVersion string `mapstructure:"min_version" yaml:"min_version,omitempty"` | ||
SkipOutput []string `mapstructure:"skip_output" yaml:"skip_output,omitempty"` | ||
SourceDir string `mapstructure:"source_dir" yaml:"source_dir,omitempty"` | ||
SourceDirLocal string `mapstructure:"source_dir_local" yaml:"source_dir_local,omitempty"` | ||
Rc string `mapstructure:"rc" yaml:",omitempty"` | ||
NoTTY bool `mapstructure:"no_tty" yaml:"no_tty,omitempty"` | ||
|
||
Hooks map[string]*Hook | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
return version.CheckCovered(c.MinVersion) | ||
} | ||
|
||
func (c *Config) Dump() error { | ||
encoder := yaml.NewEncoder(os.Stdout) | ||
encoder.SetIndent(dumpIndent) | ||
defer encoder.Close() | ||
|
||
err := encoder.Encode(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package lefthook | ||
|
||
import ( | ||
"github.com/evilmartians/lefthook/internal/config" | ||
"github.com/evilmartians/lefthook/internal/log" | ||
) | ||
|
||
func Dump(opts *Options) { | ||
lefthook, err := initialize(opts) | ||
if err != nil { | ||
log.Errorf("couldn't initialize lefthook: %s\n", err) | ||
return | ||
} | ||
|
||
cfg, err := config.Load(lefthook.Fs, lefthook.repo) | ||
if err != nil { | ||
log.Errorf("couldn't load config: %s\n", err) | ||
return | ||
} | ||
|
||
if err := cfg.Dump(); err != nil { | ||
log.Errorf("couldn't dump config: %s\n", err) | ||
return | ||
} | ||
} |