func Parse(allowIntersperse bool) {
	CommandLine.Parse(allowIntersperse, os.Args[1:])
}
Parse parses the command-line flags from os.Args[1:].  Must be called
after all flags are defined and before flags are accessed by the program.
If allowIntersperse is set, arguments and flags can be interspersed, that
is flags can follow positional arguments.
package gnuflag
import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
	"strings"
	"time"
	"unicode/utf8"
)
var ErrHelp = errors.New("flag: help requested")
type boolValue bool
func newBoolValue(val bool, p *bool) *boolValue {
	*p = val
	return (*boolValue)(p)
}
func (b *boolValue) Set(s string) error {
	v, err := strconv.ParseBool(s)
	*b = boolValue(v)
	return err
}
func (b *boolValue) Get() interface{} { return bool(*b) }
func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
func (b *boolValue) IsBoolFlag() bool { return true }
type boolFlag interface {
	Value
	IsBoolFlag() bool
}
type intValue int
func newIntValue(val int, p *int) *intValue {
	*p = val
	return (*intValue)(p)
}
func (i *intValue) Set(s string) error {
	v, err := strconv.ParseInt(s, 0, 64)
	*i = intValue(v)
	return err
}
func (i *intValue) Get() interface{} { return int(*i) }
func (i *intValue) String() string { return fmt.Sprintf("%v", *i) }
type int64Value int64
func newInt64Value(val int64, p *int64) *int64Value {
	*p = val
	return (*int64Value)(p)
}
func (i *int64Value) Set(s string) error {
	v, err := strconv.ParseInt(s, 0, 64)
	*i = int64Value(v)
	return err
}
func (i *int64Value) Get() interface{} { return int64(*i) }
func (i *int64Value) String() string { return fmt.Sprintf("%v", *i) }
type uintValue uint
func newUintValue(val uint, p *uint) *uintValue {
	*p = val
	return (*uintValue)(p)
}
func (i *uintValue) Set(s string) error {
	v, err := strconv.ParseUint(s, 0, 64)
	*i = uintValue(v)
	return err
}
func (i *uintValue) Get() interface{} { return uint(*i) }
func (i *uintValue) String() string { return fmt.Sprintf("%v", *i) }
type uint64Value uint64
func newUint64Value(val uint64, p *uint64) *uint64Value {
	*p = val
	return (*uint64Value)(p)
}
func (i *uint64Value) Set(s string) error {
	v, err := strconv.ParseUint(s, 0, 64)
	*i = uint64Value(v)
	return err
}
func (i *uint64Value) Get() interface{} { return uint64(*i) }
func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i) }
type stringValue string
func newStringValue(val string, p *string) *stringValue {
	*p = val
	return (*stringValue)(p)
}
func (s *stringValue) Set(val string) error {
	*s = stringValue(val)
	return nil
}
func (s *stringValue) Get() interface{} { return string(*s) }
func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
type float64Value float64
func newFloat64Value(val float64, p *float64) *float64Value {
	*p = val
	return (*float64Value)(p)
}
func (f *float64Value) Set(s string) error {
	v, err := strconv.ParseFloat(s, 64)
	*f = float64Value(v)
	return err
}
func (f *float64Value) Get() interface{} { return float64(*f) }
func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) }
type durationValue time.Duration
func newDurationValue(val time.Duration, p *time.Duration) *durationValue {
	*p = val
	return (*durationValue)(p)
}
func (d *durationValue) Set(s string) error {
	v, err := time.ParseDuration(s)
	*d = durationValue(v)
	return err
}
func (d *durationValue) Get() interface{} { return time.Duration(*d) }
func (d *durationValue) String() string { return (*time.Duration)(d).String() }
type Value interface {
	String() string
	Set(string) error
}
type Getter interface {
	Value
	Get() interface{}
}
type ErrorHandling int
const (
	ContinueOnError ErrorHandling = iota
	ExitOnError
	PanicOnError
)
type FlagSet struct {
	Usage func()
	name             string
	parsed           bool
	actual           map[string]*Flag
	formal           map[string]*Flag
	args             []string  
	procArgs         []string  
	procFlag         string    
	allowIntersperse bool      
	exitOnError      bool      
	errorHandling    ErrorHandling
	output           io.Writer  
}
type Flag struct {
	Name     string  
	Usage    string  
	Value    Value   
	DefValue string  
}
func sortFlags(flags map[string]*Flag) []*Flag {
	list := make(sort.StringSlice, len(flags))
	i := 0
	for _, f := range flags {
		list[i] = f.Name
		i++
	}
	list.Sort()
	result := make([]*Flag, len(list))
	for i, name := range list {
		result[i] = flags[name]
	}
	return result
}
func (f *FlagSet) out() io.Writer {
	if f.output == nil {
		return os.Stderr
	}
	return f.output
}
func (f *FlagSet) SetOutput(output io.Writer) {
	f.output = output
}
func (f *FlagSet) VisitAll(fn func(*Flag)) {
	for _, flag := range sortFlags(f.formal) {
		fn(flag)
	}
}
func VisitAll(fn func(*Flag)) {
	CommandLine.VisitAll(fn)
}
func (f *FlagSet) Visit(fn func(*Flag)) {
	for _, flag := range sortFlags(f.actual) {
		fn(flag)
	}
}
func Visit(fn func(*Flag)) {
	CommandLine.Visit(fn)
}
func (f *FlagSet) Lookup(name string) *Flag {
	return f.formal[name]
}
func Lookup(name string) *Flag {
	return CommandLine.formal[name]
}
func (f *FlagSet) Set(name, value string) error {
	flag, ok := f.formal[name]
	if !ok {
		return fmt.Errorf("no such flag -%v", name)
	}
	err := flag.Value.Set(value)
	if err != nil {
		return err
	}
	if f.actual == nil {
		f.actual = make(map[string]*Flag)
	}
	f.actual[name] = flag
	return nil
}
func Set(name, value string) error {
	return CommandLine.Set(name, value)
}
type flagsByLength []*Flag
func (f flagsByLength) Less(i, j int) bool {
	s1, s2 := f[i].Name, f[j].Name
	if len(s1) != len(s2) {
		return len(s1) < len(s2)
	}
	return s1 < s2
}
func (f flagsByLength) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}
func (f flagsByLength) Len() int {
	return len(f)
}
type flagsByName [][]*Flag
func (f flagsByName) Less(i, j int) bool {
	return f[i][0].Name < f[j][0].Name
}
func (f flagsByName) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}
func (f flagsByName) Len() int {
	return len(f)
}
func (f *FlagSet) PrintDefaults() {
	flags := make(map[interface{}]flagsByLength)
	f.VisitAll(func(f *Flag) {
		flags[f.Value] = append(flags[f.Value], f)
	})
	var byName flagsByName
	for _, f := range flags {
		sort.Sort(f)
		byName = append(byName, f)
	}
	sort.Sort(byName)
	var line bytes.Buffer
	for _, fs := range byName {
		line.Reset()
		for i, f := range fs {
			if i > 0 {
				line.WriteString(", ")
			}
			line.WriteString(flagWithMinus(f.Name))
		}
		format := "%s  (= %s)\n    %s\n"
		if _, ok := fs[0].Value.(*stringValue); ok {
			format = "%s (= %q)\n    %s\n"
		}
		fmt.Fprintf(f.out(), format, line.Bytes(), fs[0].DefValue, fs[0].Usage)
	}
}
func PrintDefaults() {
	CommandLine.PrintDefaults()
}
func defaultUsage(f *FlagSet) {
	if f.name == "" {
		fmt.Fprintf(f.out(), "Usage:\n")
	} else {
		fmt.Fprintf(f.out(), "Usage of %s:\n", f.name)
	}
	f.PrintDefaults()
}
var Usage = func() {
	fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
	PrintDefaults()
}
func (f *FlagSet) NFlag() int { return len(f.actual) }
func NFlag() int { return len(CommandLine.actual) }
func (f *FlagSet) Arg(i int) string {
	if i < 0 || i >= len(f.args) {
		return ""
	}
	return f.args[i]
}
func Arg(i int) string {
	return CommandLine.Arg(i)
}
func (f *FlagSet) NArg() int { return len(f.args) }
func NArg() int { return len(CommandLine.args) }
func (f *FlagSet) Args() []string { return f.args }
func Args() []string { return CommandLine.args }
func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {
	f.Var(newBoolValue(value, p), name, usage)
}
func BoolVar(p *bool, name string, value bool, usage string) {
	CommandLine.Var(newBoolValue(value, p), name, usage)
}
func (f *FlagSet) Bool(name string, value bool, usage string) *bool {
	p := new(bool)
	f.BoolVar(p, name, value, usage)
	return p
}
func Bool(name string, value bool, usage string) *bool {
	return CommandLine.Bool(name, value, usage)
}
func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
	f.Var(newIntValue(value, p), name, usage)
}
func IntVar(p *int, name string, value int, usage string) {
	CommandLine.Var(newIntValue(value, p), name, usage)
}
func (f *FlagSet) Int(name string, value int, usage string) *int {
	p := new(int)
	f.IntVar(p, name, value, usage)
	return p
}
func Int(name string, value int, usage string) *int {
	return CommandLine.Int(name, value, usage)
}
func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) {
	f.Var(newInt64Value(value, p), name, usage)
}
func Int64Var(p *int64, name string, value int64, usage string) {
	CommandLine.Var(newInt64Value(value, p), name, usage)
}
func (f *FlagSet) Int64(name string, value int64, usage string) *int64 {
	p := new(int64)
	f.Int64Var(p, name, value, usage)
	return p
}
func Int64(name string, value int64, usage string) *int64 {
	return CommandLine.Int64(name, value, usage)
}
func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
	f.Var(newUintValue(value, p), name, usage)
}
func UintVar(p *uint, name string, value uint, usage string) {
	CommandLine.Var(newUintValue(value, p), name, usage)
}
func (f *FlagSet) Uint(name string, value uint, usage string) *uint {
	p := new(uint)
	f.UintVar(p, name, value, usage)
	return p
}
func Uint(name string, value uint, usage string) *uint {
	return CommandLine.Uint(name, value, usage)
}
func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) {
	f.Var(newUint64Value(value, p), name, usage)
}
func Uint64Var(p *uint64, name string, value uint64, usage string) {
	CommandLine.Var(newUint64Value(value, p), name, usage)
}
func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
	p := new(uint64)
	f.Uint64Var(p, name, value, usage)
	return p
}
func Uint64(name string, value uint64, usage string) *uint64 {
	return CommandLine.Uint64(name, value, usage)
}
func (f *FlagSet) StringVar(p *string, name string, value string, usage string) {
	f.Var(newStringValue(value, p), name, usage)
}
func StringVar(p *string, name string, value string, usage string) {
	CommandLine.Var(newStringValue(value, p), name, usage)
}
func (f *FlagSet) String(name string, value string, usage string) *string {
	p := new(string)
	f.StringVar(p, name, value, usage)
	return p
}
func String(name string, value string, usage string) *string {
	return CommandLine.String(name, value, usage)
}
func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {
	f.Var(newFloat64Value(value, p), name, usage)
}
func Float64Var(p *float64, name string, value float64, usage string) {
	CommandLine.Var(newFloat64Value(value, p), name, usage)
}
func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {
	p := new(float64)
	f.Float64Var(p, name, value, usage)
	return p
}
func Float64(name string, value float64, usage string) *float64 {
	return CommandLine.Float64(name, value, usage)
}
func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
	f.Var(newDurationValue(value, p), name, usage)
}
func DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
	CommandLine.Var(newDurationValue(value, p), name, usage)
}
func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration {
	p := new(time.Duration)
	f.DurationVar(p, name, value, usage)
	return p
}
func Duration(name string, value time.Duration, usage string) *time.Duration {
	return CommandLine.Duration(name, value, usage)
}
func (f *FlagSet) Var(value Value, name string, usage string) {
	flag := &Flag{name, usage, value, value.String()}
	_, alreadythere := f.formal[name]
	if alreadythere {
		fmt.Fprintf(f.out(), "%s flag redefined: %s\n", f.name, name)
		panic("flag redefinition")  
	}
	if f.formal == nil {
		f.formal = make(map[string]*Flag)
	}
	f.formal[name] = flag
}
func Var(value Value, name string, usage string) {
	CommandLine.Var(value, name, usage)
}
func (f *FlagSet) failf(format string, a ...interface{}) error {
	err := fmt.Errorf(format, a...)
	fmt.Fprintln(f.out(), err)
	f.usage()
	return err
}
func (f *FlagSet) usage() {
	if f.Usage == nil {
		if f == CommandLine {
			Usage()
		} else {
			defaultUsage(f)
		}
	} else {
		f.Usage()
	}
}
func (f *FlagSet) parseOne() (flagName string, long, finished bool, err error) {
	if len(f.procArgs) == 0 {
		finished = true
		return
	}
	if flag := f.procFlag; len(flag) > 0 {
		_, n := utf8.DecodeRuneInString(flag)
		f.procFlag = flag[n:]
		flagName = flag[0:n]
		return
	}
	a := f.procArgs[0]
	if a == "-" || a == "" || a[0] != '-' {
		if f.allowIntersperse {
			f.args = append(f.args, a)
			f.procArgs = f.procArgs[1:]
			return
		}
		f.args = append(f.args, f.procArgs...)
		f.procArgs = nil
		finished = true
		return
	}
	if f.procArgs[0] == "--" {
		f.args = append(f.args, f.procArgs[1:]...)
		f.procArgs = nil
		finished = true
		return
	}
	if a[1] == '-' {
		long = true
		i := strings.Index(a, "=")
		if i < 0 {
			f.procArgs = f.procArgs[1:]
			flagName = a[2:]
			return
		}
		flagName = a[2:i]
		if flagName == "" {
			err = fmt.Errorf("empty flag in argument %q", a)
			return
		}
		f.procArgs = f.procArgs[1:]
		f.procFlag = a[i:]
		return
	}
	a = a[1:]
	_, n := utf8.DecodeRuneInString(a)
	flagName = a[0:n]
	f.procFlag = a[n:]
	f.procArgs = f.procArgs[1:]
	return
}
func flagWithMinus(name string) string {
	if len(name) > 1 {
		return "--" + name
	}
	return "-" + name
}
func (f *FlagSet) parseFlagArg(name string, long bool) (finished bool, err error) {
	m := f.formal
	flag, alreadythere := m[name]  
	if !alreadythere {
		if name == "help" || name == "h" {  
			f.usage()
			return false, ErrHelp
		}
		return false, f.failf("flag provided but not defined: %s", flagWithMinus(name))
	}
	if fv, ok := flag.Value.(boolFlag); ok && fv.IsBoolFlag() && !strings.HasPrefix(f.procFlag, "=") {
		if err := fv.Set("true"); err != nil {
			return false, f.failf("invalid boolean flag %s: %v", name, err)
		}
	} else {
		var hasValue bool
		var value string
		if f.procFlag != "" {
			value = f.procFlag
			if long {
				if value[0] != '=' {
					panic("no leading '=' in long flag")
				}
				value = value[1:]
			}
			hasValue = true
			f.procFlag = ""
		}
		if !hasValue && len(f.procArgs) > 0 {
			hasValue = true
			value, f.procArgs = f.procArgs[0], f.procArgs[1:]
		}
		if !hasValue {
			return false, f.failf("flag needs an argument: %s", flagWithMinus(name))
		}
		if err := flag.Value.Set(value); err != nil {
			return false, f.failf("invalid value %q for flag %s: %v", value, flagWithMinus(name), err)
		}
	}
	if f.actual == nil {
		f.actual = make(map[string]*Flag)
	}
	f.actual[name] = flag
	return
}
func (f *FlagSet) Parse(allowIntersperse bool, arguments []string) error {
	f.parsed = true
	f.procArgs = arguments
	f.procFlag = ""
	f.args = nil
	f.allowIntersperse = allowIntersperse
	for {
		name, long, finished, err := f.parseOne()
		if !finished {
			if name != "" {
				finished, err = f.parseFlagArg(name, long)
			}
		}
		if err != nil {
			switch f.errorHandling {
			case ContinueOnError:
				return err
			case ExitOnError:
				os.Exit(2)
			case PanicOnError:
				panic(err)
			}
		}
		if !finished {
			continue
		}
		if err == nil {
			break
		}
	}
	return nil
}
func (f *FlagSet) Parsed() bool {
	return f.parsed
}