aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-09-19 11:40:48 +0200
committerBjørn Erik Pedersen <[email protected]>2024-09-19 12:26:04 +0200
commit22a9f3fc98b4c6ebcade7ad11bd231e978aa58cd (patch)
tree291e6144a9d9c353d089940b9eff462970c376b4 /modules
parente363964f2fcbeabe4264eaa9d7f803c9989ad096 (diff)
downloadhugo-22a9f3fc98b4c6ebcade7ad11bd231e978aa58cd.tar.gz
hugo-22a9f3fc98b4c6ebcade7ad11bd231e978aa58cd.zip
modules: Improve console output on hugo mod init
Replace some of the stderr output from the Go command to match the Hugo commands needed: ``` go: creating new go.mod: module github.com/bep/foo hugo: to add module requirements and sums: hugo mod tidy ``` See #11458
Diffstat (limited to 'modules')
-rw-r--r--modules/client.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/client.go b/modules/client.go
index 70b3ac485..404605c8c 100644
--- a/modules/client.go
+++ b/modules/client.go
@@ -633,7 +633,7 @@ func (c *Client) runGo(
argsv := collections.StringSliceToInterfaceSlice(args)
argsv = append(argsv, hexec.WithEnviron(c.environ))
- argsv = append(argsv, hexec.WithStderr(io.MultiWriter(stderr, os.Stderr)))
+ argsv = append(argsv, hexec.WithStderr(goOutputReplacerWriter{w: io.MultiWriter(stderr, os.Stderr)}))
argsv = append(argsv, hexec.WithStdout(stdout))
argsv = append(argsv, hexec.WithDir(c.ccfg.WorkingDir))
argsv = append(argsv, hexec.WithContext(ctx))
@@ -679,6 +679,24 @@ If you then run 'hugo mod graph' it should resolve itself to the most recent ver
return nil
}
+var goOutputReplacer = strings.NewReplacer(
+ "go: to add module requirements and sums:", "hugo: to add module requirements and sums:",
+ "go mod tidy", "hugo mod tidy",
+)
+
+type goOutputReplacerWriter struct {
+ w io.Writer
+}
+
+func (w goOutputReplacerWriter) Write(p []byte) (n int, err error) {
+ s := goOutputReplacer.Replace(string(p))
+ _, err = w.w.Write([]byte(s))
+ if err != nil {
+ return 0, err
+ }
+ return len(p), nil
+}
+
func (c *Client) tidy(mods Modules, goModOnly bool) error {
isGoMod := make(map[string]bool)
for _, m := range mods {