Skip to content

Commit

Permalink
commands: Add some more info to "hugo config mounts"
Browse files Browse the repository at this point in the history
* Add owner path and version.
* Also add thme meta info and Hugo version when run with -v flag
  • Loading branch information
bep committed Jun 27, 2021
1 parent 19aa95f commit 6a365c2
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *configCmd) printMounts(cmd *cobra.Command, args []string) error {
allModules := cfg.Cfg.Get("allmodules").(modules.Modules)

for _, m := range allModules {
if err := parser.InterfaceToConfig(&modMounts{m: m}, metadecoders.JSON, os.Stdout); err != nil {
if err := parser.InterfaceToConfig(&modMounts{m: m, verbose: c.verbose}, metadecoders.JSON, os.Stdout); err != nil {
return err
}
}
Expand Down Expand Up @@ -115,7 +115,8 @@ func (c *configCmd) printConfig(cmd *cobra.Command, args []string) error {
}

type modMounts struct {
m modules.Module
verbose bool
m modules.Module
}

type modMount struct {
Expand All @@ -135,13 +136,45 @@ func (m *modMounts) MarshalJSON() ([]byte, error) {
})
}

var ownerPath string
if m.m.Owner() != nil {
ownerPath = m.m.Owner().Path()
}

if m.verbose {
config := m.m.Config()
return json.Marshal(&struct {
Path string `json:"path"`
Version string `json:"version"`
Owner string `json:"owner"`
Dir string `json:"dir"`
Meta map[string]interface{} `json:"meta"`
HugoVersion modules.HugoVersion `json:"hugoVersion"`

Mounts []modMount `json:"mounts"`
}{
Path: m.m.Path(),
Version: m.m.Version(),
Owner: ownerPath,
Dir: m.m.Dir(),
Meta: config.Params,
HugoVersion: config.HugoVersion,
Mounts: mounts,
})
}

return json.Marshal(&struct {
Path string `json:"path"`
Dir string `json:"dir"`
Mounts []modMount `json:"mounts"`
Path string `json:"path"`
Version string `json:"version"`
Owner string `json:"owner"`
Dir string `json:"dir"`
Mounts []modMount `json:"mounts"`
}{
Path: m.m.Path(),
Dir: m.m.Dir(),
Mounts: mounts,
Path: m.m.Path(),
Version: m.m.Version(),
Owner: ownerPath,
Dir: m.m.Dir(),
Mounts: mounts,
})

}

0 comments on commit 6a365c2

Please sign in to comment.