Last active
August 29, 2015 14:07
-
-
Save matope/64dd81d85592fd1be2dc to your computer and use it in GitHub Desktop.
double-dash hyphen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
) | |
var hoge *string | |
var str string | |
func init() { | |
hoge = flag.String("hoge", "default-value", "First string option") | |
flag.StringVar(&str, "str", "default-value", "Second string option") | |
} | |
func main() { | |
myParse() | |
fmt.Println("hoge:", *hoge) | |
fmt.Println("str:", str) | |
} | |
func myParse() { | |
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) | |
fs.Usage = flag.Usage | |
flag.CommandLine.VisitAll(func(f *flag.Flag) { | |
fs.Var(f.Value, f.Name, f.Usage) | |
fs.Var(f.Value, "-"+f.Name, f.Usage) | |
}) | |
fs.Parse(os.Args[1:]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment