Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-07-31 11:31:26 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-07-31 13:10:05 +0300
commitd7c233afee6a16b1947f60b7e5450e40612997bb (patch)
tree91c87d17642655308ab9806e5afcb9b77415541f /commands
parent45ee8a7a52213bf394c7f41a72be78084ddc789a (diff)
commands: Add "hugo config mounts" command
This prints the effective file mounts in a project. Fixes #6144
Diffstat (limited to 'commands')
-rw-r--r--commands/config.go66
1 files changed, 64 insertions, 2 deletions
diff --git a/commands/config.go b/commands/config.go
index 64f0cdbbf..72c2a0d97 100644
--- a/commands/config.go
+++ b/commands/config.go
@@ -14,11 +14,18 @@
package commands
import (
+ "encoding/json"
+ "os"
"reflect"
"regexp"
"sort"
"strings"
+ "github.com/gohugoio/hugo/parser"
+ "github.com/gohugoio/hugo/parser/metadecoders"
+
+ "github.com/gohugoio/hugo/modules"
+
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
@@ -40,14 +47,37 @@ func newConfigCmd() *configCmd {
RunE: cc.printConfig,
})
- cc.cmd.Flags().StringVarP(&cc.source, "source", "s", "", "filesystem path to read files relative from")
+ cc.cmd.PersistentFlags().StringVarP(&cc.source, "source", "s", "", "filesystem path to read files relative from")
+
+ printMountsCmd := &cobra.Command{
+ Use: "mounts",
+ Short: "Print the configured file mounts",
+ RunE: cc.printMounts,
+ }
+
+ cc.cmd.AddCommand(printMountsCmd)
return cc
}
-func (c *configCmd) printConfig(cmd *cobra.Command, args []string) error {
+func (c *configCmd) printMounts(cmd *cobra.Command, args []string) error {
cfg, err := initializeConfig(true, false, &c.hugoBuilderCommon, c, nil)
+ if err != nil {
+ return err
+ }
+ allModules := cfg.Cfg.Get("allmodules").(modules.Modules)
+
+ for _, m := range allModules {
+ if err := parser.InterfaceToConfig(&modMounts{m: m}, metadecoders.JSON, os.Stdout); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func (c *configCmd) printConfig(cmd *cobra.Command, args []string) error {
+ cfg, err := initializeConfig(true, false, &c.hugoBuilderCommon, c, nil)
if err != nil {
return err
}
@@ -83,3 +113,35 @@ func (c *configCmd) printConfig(cmd *cobra.Command, args []string) error {
return nil
}
+
+type modMounts struct {
+ m modules.Module
+}
+
+type modMount struct {
+ Source string `json:"source"`
+ Target string `json:"target"`
+ Lang string `json:"lang,omitempty"`
+}
+
+func (m *modMounts) MarshalJSON() ([]byte, error) {
+ var mounts []modMount
+
+ for _, mount := range m.m.Mounts() {
+ mounts = append(mounts, modMount{
+ Source: mount.Source,
+ Target: mount.Target,
+ Lang: mount.Lang,
+ })
+ }
+
+ return json.Marshal(&struct {
+ Path string `json:"path"`
+ Dir string `json:"dir"`
+ Mounts []modMount `json:"mounts"`
+ }{
+ Path: m.m.Path(),
+ Dir: m.m.Dir(),
+ Mounts: mounts,
+ })
+}