Skip to content

Commit

Permalink
fix: inline hook when dumping in TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed May 22, 2023
1 parent 5f58232 commit 264049a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
40 changes: 37 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,44 @@ func (c *Config) dumpTOML() error {
// log.Info(string(res))

// return nil
encoder := toml.NewEncoder(os.Stdout)
encoder.SetIndentTables(false)

err := encoder.Encode(c)
res := make(map[string]interface{})

if c.Colors != nil {
res["colors"] = c.Colors
}
if len(c.Extends) != 0 {
res["extends"] = c.Extends
}
if len(c.Remote.GitURL) != 0 {
res["remote"] = c.Remote
}
if len(c.MinVersion) != 0 {
res["min_version"] = c.MinVersion
}
if len(c.SkipOutput) != 0 {
res["skip_output"] = c.SkipOutput
}
if c.SourceDir != DefaultSourceDir {
res["source_dir"] = c.SourceDir
}
if c.SourceDirLocal != DefaultSourceDirLocal {
res["source_dir_local"] = c.SourceDirLocal
}
if len(c.Rc) != 0 {
res["rc"] = c.Rc
}
if c.NoTTY {
res["no_tty"] = c.NoTTY
}

for hookName, hook := range c.Hooks {
res[hookName] = hook
}

encoder := toml.NewEncoder(os.Stdout)
// err := encoder.Encode(c)
err := encoder.Encode(res)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/config/remote.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package config

type Remote struct {
GitURL string `mapstructure:"git_url" yaml:"git_url,omitempty" json:"git_url,omitempty"`
Ref string `mapstructure:"ref" yaml:",omitempty" json:"ref,omitempty"`
Config string `mapstructure:"config" yaml:",omitempty" json:"config,omitempty"`
GitURL string `mapstructure:"git_url" yaml:"git_url,omitempty" json:"git_url,omitempty" toml:"git_url"`
Ref string `mapstructure:"ref" yaml:",omitempty" json:"ref,omitempty" toml:"ref,omitempty"`
Config string `mapstructure:"config" yaml:",omitempty" json:"config,omitempty" toml:"config,omitempty"`
}

func (r Remote) Configured() bool {
Expand Down

0 comments on commit 264049a

Please sign in to comment.