Skip to content

Commit

Permalink
actually parse the MAGEFILE_VERBOSE flag (#175)
Browse files Browse the repository at this point in the history
* actually parse the verbose flag in case someone sets it to 0
  • Loading branch information
natefinch authored Sep 21, 2018
1 parent 821dc3d commit 39f09ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ func Magefiles(magePath, goCmd string, stderr io.Writer, isDebug bool) ([]string
}
cmd.Dir = magePath
b, err = cmd.Output()
list = strings.TrimSpace(string(b))

if err != nil {
return fail(fmt.Errorf("failed to list mage gofiles: %v", err))
}

list = strings.TrimSpace(string(b))
files := []string{}
for _, f := range strings.Split(list, "||") {
if f != "" && !exclude[f] {
Expand Down
12 changes: 12 additions & 0 deletions mage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,19 @@ func TestVerboseEnv(t *testing.T) {
if inv.Verbose != true {
t.Fatalf("expected %t, but got %t ", expected, inv.Verbose)
}
}
func TestVerboseFalseEnv(t *testing.T) {
os.Setenv("MAGEFILE_VERBOSE", "0")
defer os.Unsetenv("MAGEFILE_VERBOSE")
stdout := &bytes.Buffer{}
code := ParseAndRun(ioutil.Discard, stdout, nil, []string{"-d", "testdata", "testverbose"})
if code != 0 {
t.Fatal("unexpected code", code)
}

if stdout.String() != "" {
t.Fatalf("expected no output, but got %s", stdout.String())
}
}

func TestList(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions mage/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func main() {
_ = handleError
log.SetFlags(0)
if os.Getenv("MAGEFILE_VERBOSE") == "" {
verbose, _ := strconv.ParseBool(os.Getenv("MAGEFILE_VERBOSE"))
if !verbose {
log.SetOutput(ioutil.Discard)
}
logger := log.New(os.Stderr, "", 0)
Expand Down Expand Up @@ -163,8 +164,6 @@ func main() {
os.Exit(1)
}
}
// to avoid unused import
_ = strconv.ParseBool
if len(os.Args) < 2 {
{{- if .Default}}
ignore, _ := strconv.ParseBool(os.Getenv("MAGEFILE_IGNOREDEFAULT"))
Expand Down Expand Up @@ -196,7 +195,7 @@ func main() {
switch strings.ToLower(target) {
{{range .Funcs }}
case "{{lower .TemplateName}}":
if os.Getenv("MAGEFILE_VERBOSE") != "" {
if verbose {
logger.Println("Running target:", "{{.TemplateName}}")
}
{{.TemplateString}}
Expand Down

0 comments on commit 39f09ed

Please sign in to comment.