]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: run main package when no files are listed
authorJonathan Rudenberg <jonathan@titanous.com>
Thu, 4 Apr 2013 01:04:35 +0000 (12:04 +1100)
committerAndrew Gerrand <adg@golang.org>
Thu, 4 Apr 2013 01:04:35 +0000 (12:04 +1100)
Fixes 5164.

R=golang-dev, iant, adg
CC=golang-dev
https://golang.org/cl/8119049

doc/go1.1.html
src/cmd/go/doc.go
src/cmd/go/run.go

index c367875c4f897c4157f88abbe7e61df673766dce..5f56a6afe037bf5a12ed8c196e089df7aa392d7d 100644 (file)
@@ -392,6 +392,15 @@ To update pre-Go 1 code to Go 1.1, use a Go 1.0 tool chain
 to convert the code to Go 1.0 first.
 </p>
 
+<h3 id="gorun">Changes to the go run command</h3>
+
+<p>
+The <code>go run</code> command now runs all files in the current working
+directory if no file arguments are listed. Also, the <code>go run</code>
+command now returns an error if test files are provided on the command line. In
+this sense, "<code>go run</code>" replaces "<code>go run *.go</code>".
+</p>
+
 <h3 id="platforms">Additional platforms</h3>
 
 <p>
index 6ffcf9ab6c05b72279617a845f1d1fcaab91ca65..3b22e0f04a154527aff263f2fe08eeba0688f1a2 100644 (file)
@@ -367,9 +367,10 @@ Compile and run Go program
 
 Usage:
 
-       go run [build flags] gofiles... [arguments...]
+       go run [build flags] [gofiles...] [arguments...]
 
 Run compiles and runs the main package comprising the named Go source files.
+If no files are named, it compiles and runs all non-test Go source files.
 
 For more about build flags, see 'go help build'.
 
index b50569363522cc9148bf542563f584e120785848..d8ba4dbddd805c320b7b614b88f7b0086a650a3b 100644 (file)
@@ -8,14 +8,16 @@ import (
        "fmt"
        "os"
        "os/exec"
+       "path/filepath"
        "strings"
 )
 
 var cmdRun = &Command{
-       UsageLine: "run [build flags] gofiles... [arguments...]",
+       UsageLine: "run [build flags] [gofiles...] [arguments...]",
        Short:     "compile and run Go program",
        Long: `
 Run compiles and runs the main package comprising the named Go source files.
+If no files are named, it compiles and runs all non-test Go source files.
 
 For more about build flags, see 'go help build'.
 
@@ -44,7 +46,18 @@ func runRun(cmd *Command, args []string) {
        }
        files, cmdArgs := args[:i], args[i:]
        if len(files) == 0 {
-               fatalf("go run: no go files listed")
+               allFiles, err := filepath.Glob("*.go")
+               if err != nil {
+                       fatalf("go run: %s", err)
+               }
+               for _, file := range allFiles {
+                       if !strings.HasSuffix(file, "_test.go") {
+                               files = append(files, file)
+                       }
+               }
+               if len(files) == 0 {
+                       fatalf("go run: no go files found")
+               }
        }
        for _, file := range files {
                if strings.HasSuffix(file, "_test.go") {