//
// Usage:
//
-// go mod graph
+// go mod graph [-dot]
//
// Graph prints the module requirement graph (with replacements applied)
// in text form. Each line in the output has two space-separated fields: a module
// and one of its requirements. Each module is identified as a string of the form
// path@version, except for the main module, which has no @version suffix.
//
+// The -dot flag generates the output in graphviz format that can be used
+// with a tool like dot to visually render the dependency graph.
+//
//
// Initialize new module in current directory
//
--- /dev/null
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !nacl
+
+package main_test
+
+import (
+ "bytes"
+ "io/ioutil"
+ "testing"
+
+ "cmd/go/internal/help"
+)
+
+func TestDocsUpToDate(t *testing.T) {
+ buf := new(bytes.Buffer)
+ // Match the command in mkalldocs.sh that generates alldocs.go.
+ help.Help(buf, []string{"documentation"})
+ data, err := ioutil.ReadFile("alldocs.go")
+ if err != nil {
+ t.Fatalf("error reading alldocs.go: %v", err)
+ }
+ if !bytes.Equal(data, buf.Bytes()) {
+ t.Errorf("alldocs.go is not up to date; run mkalldocs.sh to regenerate it")
+ }
+}
)
// Help implements the 'help' command.
-func Help(args []string) {
+func Help(w io.Writer, args []string) {
// 'go help documentation' generates doc.go.
if len(args) == 1 && args[0] == "documentation" {
- fmt.Println("// Copyright 2011 The Go Authors. All rights reserved.")
- fmt.Println("// Use of this source code is governed by a BSD-style")
- fmt.Println("// license that can be found in the LICENSE file.")
- fmt.Println()
- fmt.Println("// Code generated by mkalldocs.sh; DO NOT EDIT.")
- fmt.Println("// Edit the documentation in other files and rerun mkalldocs.sh to generate this one.")
- fmt.Println()
+ fmt.Fprintln(w, "// Copyright 2011 The Go Authors. All rights reserved.")
+ fmt.Fprintln(w, "// Use of this source code is governed by a BSD-style")
+ fmt.Fprintln(w, "// license that can be found in the LICENSE file.")
+ fmt.Fprintln(w)
+ fmt.Fprintln(w, "// Code generated by mkalldocs.sh; DO NOT EDIT.")
+ fmt.Fprintln(w, "// Edit the documentation in other files and rerun mkalldocs.sh to generate this one.")
+ fmt.Fprintln(w)
buf := new(bytes.Buffer)
PrintUsage(buf, base.Go)
usage := &base.Command{Long: buf.String()}
cmds = append(cmds, cmd)
cmds = append(cmds, cmd.Commands...)
}
- tmpl(&commentWriter{W: os.Stdout}, documentationTemplate, cmds)
- fmt.Println("package main")
+ tmpl(&commentWriter{W: w}, documentationTemplate, cmds)
+ fmt.Fprintln(w, "package main")
return
}
cfg.CmdName = args[0] // for error messages
if args[0] == "help" {
- help.Help(args[1:])
+ help.Help(os.Stdout, args[1:])
return
}
}
if args[0] == "help" {
// Accept 'go mod help' and 'go mod help foo' for 'go help mod' and 'go help mod foo'.
- help.Help(append(strings.Split(cfg.CmdName, " "), args[1:]...))
+ help.Help(os.Stdout, append(strings.Split(cfg.CmdName, " "), args[1:]...))
return
}
cfg.CmdName += " " + args[0]
set -e
go build -o go.latest
+# If the command used to generate alldocs.go changes, update TestDocsUpToDate in
+# help_test.go.
./go.latest help documentation >alldocs.go
gofmt -w alldocs.go
rm go.latest