hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 9b83f45b6dcafa6e50df80a4786d6a36400a47fe
parent 7fdd2b95e20f322b0a47f63ff1010a04f47ce67b
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Fri,  9 Apr 2021 08:07:22 +0200

Add complete dependency list in "hugo env -v"

Fixes #8400

Diffstat:
Mcommands/env.go | 17++++++++++++++++-
Mcommon/hugo/hugo.go | 29+++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/commands/env.go b/commands/env.go
@@ -16,6 +16,8 @@ package commands
 import (
 	"runtime"
 
+	"github.com/gohugoio/hugo/common/hugo"
+
 	"github.com/spf13/cobra"
 	jww "github.com/spf13/jwalterweatherman"
 )
@@ -31,15 +33,28 @@ func newEnvCmd() *envCmd {
 		baseCmd: newBaseCmd(&cobra.Command{
 			Use:   "env",
 			Short: "Print Hugo version and environment info",
-			Long:  `Print Hugo version and environment info. This is useful in Hugo bug reports.`,
+			Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.
+
+If you add the -v flag, you will get a full dependency list.
+`,
 			RunE: func(cmd *cobra.Command, args []string) error {
 				printHugoVersion()
 				jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS)
 				jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH)
 				jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version())
 
+				isVerbose, _ := cmd.Flags().GetBool("verbose")
+
+				if isVerbose {
+					deps := hugo.GetDependencyList()
+					for _, dep := range deps {
+						jww.FEEDBACK.Printf("%s\n", dep)
+					}
+				}
+
 				return nil
 			},
 		}),
 	}
+
 }
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go
@@ -18,6 +18,8 @@ import (
 	"html/template"
 	"os"
 	"path/filepath"
+	"runtime/debug"
+	"sort"
 	"strings"
 
 	"github.com/gohugoio/hugo/hugofs/files"
@@ -107,3 +109,30 @@ func GetExecEnviron(workDir string, cfg config.Provider, fs afero.Fs) []string {
 
 	return env
 }
+
+// GetDependencyList returns a sorted dependency list on the format package="version".
+// It includes both Go dependencies and (a manually maintained) list of C(++) dependencies.
+func GetDependencyList() []string {
+	var deps []string
+
+	formatDep := func(path, version string) string {
+		return fmt.Sprintf("%s=%q", path, version)
+	}
+
+	if IsExtended {
+		deps = append(deps, formatDep("github.com/sass/libsass", "3.6.4"))
+	}
+
+	bi, ok := debug.ReadBuildInfo()
+	if !ok {
+		return deps
+	}
+
+	for _, dep := range bi.Deps {
+		deps = append(deps, formatDep(dep.Path, dep.Version))
+	}
+
+	sort.Strings(deps)
+
+	return deps
+}