Skip to content

Instantly share code, notes, and snippets.

@matope
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matope/64dd81d85592fd1be2dc to your computer and use it in GitHub Desktop.
Save matope/64dd81d85592fd1be2dc to your computer and use it in GitHub Desktop.
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