Repository: magefile/mage (go)

Issue:
Nitpicking over usage/help text output
Asking `mage` to display supported options yields:

```
$ mage -h
mage [options] [target]
Options:
  -f    force recreation of compiled magefile
  -h    show this help
  -init
        create a starting template if no mage files exist
  -keep
        keep intermediate mage files around after running
  -l    list mage targets in this directory
  -v    show verbose output when running mage targets
  -version
        show version info for the mage binary
```

but typing the following yields:

```
$ mage --help
mage [options] [target]
Options:
  -f    force recreation of compiled magefile
  -h    show this help
  -init
        create a starting template if no mage files exist
  -keep
        keep intermediate mage files around after running
  -l    list mage targets in this directory
  -v    show verbose output when running mage targets
  -version
        show version info for the mage binary
mage [options] [target]
Options:
  -f    force recreation of compiled magefile
  -h    show this help
  -init
        create a starting template if no mage files exist
  -keep
        keep intermediate mage files around after running
  -l    list mage targets in this directory
  -v    show verbose output when running mage targets
  -version
        show version info for the mage binary
```

instead of:

```
$ mage --help
flag provided but not defined: -help
mage [options] [target]
Options:
  -f    force recreation of compiled magefile
  -h    show this help
  -init
        create a starting template if no mage files exist
  -keep
        keep intermediate mage files around after running
  -l    list mage targets in this directory
  -v    show verbose output when running mage targets
  -version
        show version info for the mage binary
Error: flag provided but not defined: -help
```

You may want to fix [this](https://github.com/magefile/mage/blob/ca568f7054407930250eb570b76ee41c27c130ab/mage/main.go#L118-L132) :wink:

Pull request:
fix #60
fix it so that mage --help doesn't print help twice

Patch:
diff --git a/mage/main.go b/mage/main.go
index ca6510b..1f97e7c 100644
--- a/mage/main.go
+++ b/mage/main.go
@@ -122,7 +122,7 @@ func Parse(stdout io.Writer, args []string) (inv Invocation, mageInit, showVersi
 	}
 	err = fs.Parse(args)
 	if err == flag.ErrHelp {
-		fs.Usage()
+		// parse will have already called fs.Usage()
 		return inv, mageInit, showVersion, err
 	}
 	if err == nil && inv.Help && len(fs.Args()) == 0 {


Test patch:
diff --git a/mage/main_test.go b/mage/main_test.go
index 514c448..180f75b 100644
--- a/mage/main_test.go
+++ b/mage/main_test.go
@@ -2,6 +2,7 @@ package mage
 
 import (
 	"bytes"
+	"flag"
 	"fmt"
 	"io/ioutil"
 	"log"
@@ -294,3 +295,22 @@ func TestParse(t *testing.T) {
 	}
 
 }
+
+func TestParseHelp(t *testing.T) {
+	buf := &bytes.Buffer{}
+	_, _, _, err := Parse(buf, []string{"-h"})
+	if err != flag.ErrHelp {
+		t.Fatal("unexpected error", err)
+	}
+	buf2 := &bytes.Buffer{}
+	_, _, _, err = Parse(buf2, []string{"--help"})
+	if err != flag.ErrHelp {
+		t.Fatal("unexpected error", err)
+	}
+	s := buf.String()
+	s2 := buf2.String()
+	if s != s2 {
+		t.Fatalf("expected -h and --help to produce same output, but got different.\n\n-h:\n%s\n\n--help:\n%s", s, s2)
+	}
+
+}