1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-19 18:47:05 +00:00

Implement to parse -n flag #7

This commit is contained in:
teru
2016-08-28 17:06:52 +09:00
parent 0118652074
commit 50d429ad78

View File

@@ -1,6 +1,9 @@
package command package command
import ( import (
"bytes"
"flag"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
@@ -11,3 +14,17 @@ type Meta struct {
SubCmdName string SubCmdName string
Version string Version string
} }
// noCommitFlag returns true if `pargs` has "-n" flag.
// `pargs` is overwrites with non-flag arguments.
func noCommitFlag(pargs *[]string) (bool, error) {
nFlag := false
flagSet := flag.NewFlagSet("", flag.ContinueOnError)
flagSet.SetOutput(&bytes.Buffer{})
flagSet.BoolVar(&nFlag, "n", nFlag, "")
err := flagSet.Parse(*pargs)
*pargs = flagSet.Args()
return nFlag, err
}