Skip to content

Commit

Permalink
Remove flag options from looper command, pass all command line option…
Browse files Browse the repository at this point in the history
…s directly to `go test`.

After the ability to pass arbitrary flags to `go test` [nathany#26](nathany#26), there was no reason to keep the `-tags` flag.

Removing `-tags` leaves only `-debug` and that makes sense to move to an environment variable (`$LOOPER_DEBUG`).

Removing looper flags allows us to drop the need for `--` to pass options to `go test`, so now we can call looper just like go test.
  • Loading branch information
ErebusBat committed Jun 15, 2015
1 parent 67b3ca2 commit 594cb33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
28 changes: 15 additions & 13 deletions gat/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
)

type Run struct {
Tags string

// Additional args to pass to `go test`
Args []string
}
Expand All @@ -27,17 +25,7 @@ func (run Run) RunOnChange(file string) {
}

func (run Run) goTest(test_files string) {
args := []string{"test"}
if len(run.Tags) > 0 {
args = append(args, []string{"-tags", run.Tags}...)
}

for _, arg := range run.Args {
args = append(args, arg)
}

args = append(args, test_files)

args := run.buildCmdArgs(test_files)
command := "go"

if _, err := os.Stat("Godeps/Godeps.json"); err == nil {
Expand All @@ -63,3 +51,17 @@ func (run Run) goTest(test_files string) {
func isGoFile(file string) bool {
return filepath.Ext(file) == ".go"
}

func (run Run) buildCmdArgs(test_files string) []string {
// go test command: test
args := []string{"test"}

// additional args passed in on looper cmd line
for _, arg := range run.Args {
args = append(args, arg)
}

args = append(args, test_files)

return args
}
23 changes: 7 additions & 16 deletions looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"strconv"

"github.com/nathany/looper/gat"
)
Expand Down Expand Up @@ -45,22 +44,14 @@ out:
}

func main() {
var tags string
var debug bool
flag.StringVar(&tags, "tags", "", "a list of build tags for testing.")
flag.BoolVar(&debug, "debug", false, "adds additional logging")
flag.Usage = func() {
fmt.Printf("Usage: %s [options] [-- [go test options]]\n", os.Args[0])
flag.PrintDefaults()
fmt.Println(`
EXAMPLE: Specify a -run option to go test, run looper in debug mode:
looper -debug -- -run MyTest`)
}
flag.Parse()
// Get debug status from env var, if error ignore and debug is off
debug, _ := strconv.ParseBool(os.Getenv("LOOPER_DEBUG"))

runner := gat.Run{Tags: tags, Args: flag.Args()}
// Pass all args to go test, except the name of the looper command
gtargs := os.Args[1:len(os.Args)]
runner := gat.Run{Args: gtargs}

Header()
Header(gtargs)
if debug {
DebugEnabled()
}
Expand Down
14 changes: 7 additions & 7 deletions print.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/koyachi/go-term-ansicolor/ansicolor"
)

func Header() {
fmt.Println(ansicolor.Cyan("Looper 0.3.2 is watching your files"))
func Header(gtargs []string) {
fmt.Println(ansicolor.Cyan("Looper 0.3.4 is watching your files"))

testArgLen := len(flag.Args())
if testArgLen > 0 {
fmt.Printf(ansicolor.Green("Passing %d addition argument(s) to go test:\n"), testArgLen)
for _, arg := range flag.Args() {
if len(gtargs) > 0 {
fmt.Printf(ansicolor.Green("Passing %d addition argument(s) to go test:\n"), len(gtargs))
for _, arg := range os.Args {
fmt.Printf(ansicolor.Green(" %s\n"), arg)
}
fmt.Println(ansicolor.Green(" <files>"))
}

fmt.Println("Type " + ansicolor.Magenta("help") + " for help.\n")
Expand Down

0 comments on commit 594cb33

Please sign in to comment.