summaryrefslogtreecommitdiff
path: root/src/cmd/go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/go')
-rw-r--r--src/cmd/go/build.go5
-rw-r--r--src/cmd/go/doc.go17
-rw-r--r--src/cmd/go/fmt.go21
-rw-r--r--src/cmd/go/help.go4
-rw-r--r--src/cmd/go/main.go30
-rw-r--r--src/cmd/go/run.go4
-rw-r--r--src/cmd/go/vet.go9
7 files changed, 75 insertions, 15 deletions
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
index 4bb83f161..767ddfd40 100644
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -152,6 +152,11 @@ func addBuildFlags(cmd *Command) {
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 {
diff --git a/src/cmd/go/doc.go b/src/cmd/go/doc.go
index 32ede3964..5e7b10692 100644
--- a/src/cmd/go/doc.go
+++ b/src/cmd/go/doc.go
@@ -145,7 +145,7 @@ Run godoc on package sources
Usage:
- go doc [packages]
+ go doc [-n] [-x] [packages]
Doc runs the godoc command on the packages named by the
import paths.
@@ -153,6 +153,9 @@ 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.
@@ -192,7 +195,7 @@ Run gofmt on package sources
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.
@@ -200,6 +203,9 @@ 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.
@@ -414,7 +420,7 @@ Run go tool vet on packages
Usage:
- go vet [packages]
+ go vet [-n] [-x] [packages]
Vet runs the Go vet command on the packages named by the import paths.
@@ -423,6 +429,9 @@ For more about specifying packages, see 'go help packages'.
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.
@@ -537,7 +546,7 @@ in those files and ignoring any other files in the directory.
Remote import path syntax
-An import path (see 'go help importpath') denotes a package
+An import path (see 'go help packages') denotes a package
stored in the local file system. Certain import paths also
describe how to obtain the source code for the package using
a revision control system.
diff --git a/src/cmd/go/fmt.go b/src/cmd/go/fmt.go
index cea9b0a51..b1aba32f3 100644
--- a/src/cmd/go/fmt.go
+++ b/src/cmd/go/fmt.go
@@ -4,9 +4,14 @@
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
@@ -15,6 +20,9 @@ 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.
@@ -32,7 +40,7 @@ func runFmt(cmd *Command, args []string) {
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
@@ -41,6 +49,9 @@ 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.
@@ -53,6 +64,10 @@ func runDoc(cmd *Command, args []string) {
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)
+ }
}
}
diff --git a/src/cmd/go/help.go b/src/cmd/go/help.go
index 47ea0c711..7539753af 100644
--- a/src/cmd/go/help.go
+++ b/src/cmd/go/help.go
@@ -61,7 +61,7 @@ var helpRemote = &Command{
Short: "remote import path syntax",
Long: `
-An import path (see 'go help importpath') denotes a package
+An import path (see 'go help packages') denotes a package
stored in the local file system. Certain import paths also
describe how to obtain the source code for the package using
a revision control system.
@@ -138,7 +138,7 @@ The meta tag has the form:
<meta name="go-import" content="import-prefix vcs repo-root">
-The import-prefix is the import path correponding to the repository
+The import-prefix is the import path corresponding to the repository
root. It must be a prefix or an exact match of the package being
fetched with "go get". If it's not an exact match, another http
request is made at the prefix to verify the <meta> tags match.
diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go
index 73c2f54a7..20585d1be 100644
--- a/src/cmd/go/main.go
+++ b/src/cmd/go/main.go
@@ -144,8 +144,9 @@ func main() {
}
}
- 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.
@@ -339,6 +340,13 @@ func exitIfErrors() {
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
@@ -500,13 +508,25 @@ func matchPackagesInFS(pattern string) []string {
var pkgs []string
filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
- if err != nil || !fi.IsDir() || path == dir {
+ if err != nil || !fi.IsDir() {
return nil
}
+ if path == dir {
+ // filepath.Walk starts at dir and recurses. For the recursive case,
+ // the path is the result of filepath.Join, which calls filepath.Clean.
+ // The initial case is not Cleaned, though, so we do this explicitly.
+ //
+ // This converts a path like "./io/" to "io". Without this step, running
+ // "cd $GOROOT/src/pkg; go list ./io/..." would incorrectly skip the io
+ // package, because prepending the prefix "./" to the unclean path would
+ // result in "././io", and match("././io") returns false.
+ path = filepath.Clean(path)
+ }
- // Avoid .foo, _foo, and testdata directory trees.
+ // Avoid .foo, _foo, and testdata directory trees, but do not avoid "." or "..".
_, elem := filepath.Split(path)
- if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" {
+ dot := strings.HasPrefix(elem, ".") && elem != "." && elem != ".."
+ if dot || strings.HasPrefix(elem, "_") || elem == "testdata" {
return filepath.SkipDir
}
diff --git a/src/cmd/go/run.go b/src/cmd/go/run.go
index 94cd59296..6043b7e20 100644
--- a/src/cmd/go/run.go
+++ b/src/cmd/go/run.go
@@ -49,6 +49,10 @@ func runRun(cmd *Command, args []string) {
if p.Error != nil {
fatalf("%s", p.Error)
}
+ for _, err := range p.DepsErrors {
+ errorf("%s", err)
+ }
+ exitIfErrors()
if p.Name != "main" {
fatalf("go run: cannot run non-main package")
}
diff --git a/src/cmd/go/vet.go b/src/cmd/go/vet.go
index a672b9910..eb0b89cca 100644
--- a/src/cmd/go/vet.go
+++ b/src/cmd/go/vet.go
@@ -4,9 +4,13 @@
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.
@@ -16,6 +20,9 @@ For more about specifying packages, see 'go help packages'.
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.
`,
}