Create a gist now

Instantly share code, notes, and snippets.

@matope /main.go
Last active Aug 29, 2015

double-dash hyphen
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