diff options
author | Eric Eisner <eric.d.eisner@gmail.com> | 2012-01-06 09:23:00 +1100 |
---|---|---|
committer | Eric Eisner <eric.d.eisner@gmail.com> | 2012-01-06 09:23:00 +1100 |
commit | 3af4b98e7c24edcd3982d46bcf65a5b2f920d7fe (patch) | |
tree | 9161057cbb3848d5437010478af879b20c06ddcc /src/cmd/go/run.go | |
parent | 0929dbcd6142a91b0792fd089ea978b281bcd036 (diff) | |
download | go-3af4b98e7c24edcd3982d46bcf65a5b2f920d7fe.tar.gz |
cmd/go: Pass arguments to command for run
Command arguments are separated from input .go file arguments
by a -- separator.
R=rsc, golang-dev, adg
CC=golang-dev
http://codereview.appspot.com/5514046
Committer: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/cmd/go/run.go')
-rw-r--r-- | src/cmd/go/run.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/cmd/go/run.go b/src/cmd/go/run.go index f4df2cf9a..3ccb465a6 100644 --- a/src/cmd/go/run.go +++ b/src/cmd/go/run.go @@ -12,7 +12,7 @@ func init() { } var cmdRun = &Command{ - UsageLine: "run [-a] [-n] [-x] gofiles...", + UsageLine: "run [-a] [-n] [-x] gofiles... [-- arguments...]", Short: "compile and run Go program", Long: ` Run compiles and runs the main package comprising the named Go source files. @@ -32,16 +32,34 @@ var runX = cmdRun.Flag.Bool("x", false, "") func runRun(cmd *Command, args []string) { var b builder b.init(*runA, *runN, *runX) - p := goFilesPackage(args, "") + files, args := splitArgs(args) + p := goFilesPackage(files, "") p.target = "" // must build - not up to date a1 := b.action(modeBuild, modeBuild, p) - a := &action{f: (*builder).runProgram, deps: []*action{a1}} + a := &action{f: (*builder).runProgram, args: args, deps: []*action{a1}} b.do(a) } // runProgram is the action for running a binary that has already // been compiled. We ignore exit status. func (b *builder) runProgram(a *action) error { - run(a.deps[0].target) + args := append([]string{a.deps[0].target}, a.args...) + run(args...) return nil } + +// Return the argument slices before and after the "--" +func splitArgs(args []string) (before, after []string) { + dashes := len(args) + for i, arg := range args { + if arg == "--" { + dashes = i + break + } + } + before = args[:dashes] + if dashes < len(args) { + after = args[dashes+1:] + } + return +} |