Skip to content

Commit 22a9f3f

Browse files
committed
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
1 parent e363964 commit 22a9f3f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

modules/client.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ func (c *Client) runGo(
633633

634634
argsv := collections.StringSliceToInterfaceSlice(args)
635635
argsv = append(argsv, hexec.WithEnviron(c.environ))
636-
argsv = append(argsv, hexec.WithStderr(io.MultiWriter(stderr, os.Stderr)))
636+
argsv = append(argsv, hexec.WithStderr(goOutputReplacerWriter{w: io.MultiWriter(stderr, os.Stderr)}))
637637
argsv = append(argsv, hexec.WithStdout(stdout))
638638
argsv = append(argsv, hexec.WithDir(c.ccfg.WorkingDir))
639639
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
679679
return nil
680680
}
681681

682+
var goOutputReplacer = strings.NewReplacer(
683+
"go: to add module requirements and sums:", "hugo: to add module requirements and sums:",
684+
"go mod tidy", "hugo mod tidy",
685+
)
686+
687+
type goOutputReplacerWriter struct {
688+
w io.Writer
689+
}
690+
691+
func (w goOutputReplacerWriter) Write(p []byte) (n int, err error) {
692+
s := goOutputReplacer.Replace(string(p))
693+
_, err = w.w.Write([]byte(s))
694+
if err != nil {
695+
return 0, err
696+
}
697+
return len(p), nil
698+
}
699+
682700
func (c *Client) tidy(mods Modules, goModOnly bool) error {
683701
isGoMod := make(map[string]bool)
684702
for _, m := range mods {

0 commit comments

Comments
 (0)