cmd.Flag.Var(buildCompiler{}, "compiler", "")
}
+func addBuildFlagsNX(cmd *Command) {
+ cmd.Flag.BoolVar(&buildN, "n", false, "")
+ cmd.Flag.BoolVar(&buildX, "x", false, "")
+}
+
type stringsFlag []string
func (v *stringsFlag) Set(s string) error {
Usage:
- go doc [packages]
+ go doc [-n] [-x] [packages]
Doc runs the godoc command on the packages named by the
import paths.
For more about godoc, see 'godoc godoc'.
For more about specifying packages, see 'go help packages'.
+The -n flag prints commands that would be executed.
+The -x flag prints commands as they are executed.
+
To run godoc with specific options, run godoc itself.
See also: go fix, go fmt, go vet.
Usage:
- go fmt [packages]
+ go fmt [-n] [-x] [packages]
Fmt runs the command 'gofmt -l -w' on the packages named
by the import paths. It prints the names of the files that are modified.
For more about gofmt, see 'godoc gofmt'.
For more about specifying packages, see 'go help packages'.
+The -n flag prints commands that would be executed.
+The -x flag prints commands as they are executed.
+
To run gofmt with specific options, run gofmt itself.
See also: go doc, go fix, go vet.
Usage:
- go vet [packages]
+ go vet [-n] [-x] [packages]
Vet runs the Go vet command on the packages named by the import paths.
To run the vet tool with specific options, run 'go tool vet'.
+The -n flag prints commands that would be executed.
+The -x flag prints commands as they are executed.
+
See also: go fmt, go fix.
package main
+func init() {
+ addBuildFlagsNX(cmdFmt)
+ addBuildFlagsNX(cmdDoc)
+}
+
var cmdFmt = &Command{
Run: runFmt,
- UsageLine: "fmt [packages]",
+ UsageLine: "fmt [-n] [-x] [packages]",
Short: "run gofmt on package sources",
Long: `
Fmt runs the command 'gofmt -l -w' on the packages named
For more about gofmt, see 'godoc gofmt'.
For more about specifying packages, see 'go help packages'.
+The -n flag prints commands that would be executed.
+The -x flag prints commands as they are executed.
+
To run gofmt with specific options, run gofmt itself.
See also: go doc, go fix, go vet.
var cmdDoc = &Command{
Run: runDoc,
- UsageLine: "doc [packages]",
+ UsageLine: "doc [-n] [-x] [packages]",
Short: "run godoc on package sources",
Long: `
Doc runs the godoc command on the packages named by the
For more about godoc, see 'godoc godoc'.
For more about specifying packages, see 'go help packages'.
+The -n flag prints commands that would be executed.
+The -x flag prints commands as they are executed.
+
To run godoc with specific options, run godoc itself.
See also: go fix, go fmt, go vet.
errorf("go doc: cannot use package file list")
continue
}
- run("godoc", pkg.Dir)
+ if pkg.local {
+ run("godoc", pkg.Dir)
+ } else {
+ run("godoc", pkg.ImportPath)
+ }
}
}
}
}
- fmt.Fprintf(os.Stderr, "Unknown command %#q\n\n", args[0])
- usage()
+ fmt.Fprintf(os.Stderr, "go: unknown subcommand %#q\nRun 'go help' for usage.\n", args[0])
+ setExitStatus(2)
+ exit()
}
var usageTemplate = `Go is a tool for managing Go source code.
func run(cmdargs ...interface{}) {
cmdline := stringList(cmdargs...)
+ if buildN || buildV {
+ fmt.Printf("%s\n", strings.Join(cmdline, " "))
+ if buildN {
+ return
+ }
+ }
+
cmd := exec.Command(cmdline[0], cmdline[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
package main
+func init() {
+ addBuildFlagsNX(cmdVet)
+}
+
var cmdVet = &Command{
Run: runVet,
- UsageLine: "vet [packages]",
+ UsageLine: "vet [-n] [-x] [packages]",
Short: "run go tool vet on packages",
Long: `
Vet runs the Go vet command on the packages named by the import paths.
To run the vet tool with specific options, run 'go tool vet'.
+The -n flag prints commands that would be executed.
+The -x flag prints commands as they are executed.
+
See also: go fmt, go fix.
`,
}