func (fs *FlagSet) Parse(args []string) (err error) {
	for len(args) > 0 {
		if !((isLong(args[0]) && fs.hasLongFlag(args[0][2:])) ||
			(isShort(args[0]) && fs.hasShortFlag(args[0][1:2]))) {
			break
		}
		f := fs.FlagByName(args[0])
		args, err = f.Parse(args)
		if err != nil {
			return
		}
		if f == fs.helpFlag && f.WasSpecified {
			return ErrHelpRequest
		}
	}
	if len(args) > 0 {
		if verb, ok := fs.Verbs[args[0]]; ok {
			fs.verbFlag.value.Set(reflect.ValueOf(Verbs(args[0])))
			err := verb.Parse(args[1:])
			if err != nil {
				return err
			}
			args = args[0:0]
		}
	}
	if len(args) > 0 {
		if fs.remainderFlag == nil {
			return fmt.Errorf("Invalid trailing arguments: %v", args)
		}
		remainder := reflect.MakeSlice(fs.remainderFlag.value.Type(), len(args), len(args))
		reflect.Copy(remainder, reflect.ValueOf(args))
		fs.remainderFlag.value.Set(remainder)
	}
	for _, f := range fs.Flags {
		if f.Obligatory && !f.WasSpecified && len(f.MutexGroups) == 0 {
			return fmt.Errorf("%s must be specified", f.Name())
		}
	}
	mgs := fs.MutexGroups()
	for _, mg := range mgs {
		if !mg.IsValid() {
			return fmt.Errorf("Exactly one of %s must be specified", strings.Join(mg.Names(), ", "))
		}
	}
	return nil
}
Parse takes the command line arguments and sets the corresponding values
in the FlagSet's struct.
package goptions
import (
	"errors"
	"fmt"
	"io"
	"os"
	"reflect"
	"strings"
	"sync"
)
type FlagSet struct {
	HelpFunc
	Name          string
	helpFlag      *Flag
	remainderFlag *Flag
	shortMap      map[string]*Flag
	longMap       map[string]*Flag
	verbFlag      *Flag
	Flags []*Flag
	Verbs  map[string]*FlagSet
	parent *FlagSet
}
func NewFlagSet(name string, v interface{}) *FlagSet {
	structValue := reflect.ValueOf(v)
	if structValue.Kind() != reflect.Ptr {
		panic("Value type is not a pointer to a struct")
	}
	structValue = structValue.Elem()
	if structValue.Kind() != reflect.Struct {
		panic("Value type is not a pointer to a struct")
	}
	return newFlagset(name, structValue, nil)
}
func newFlagset(name string, structValue reflect.Value, parent *FlagSet) *FlagSet {
	var once sync.Once
	r := &FlagSet{
		Name:     name,
		Flags:    make([]*Flag, 0),
		HelpFunc: DefaultHelpFunc,
		parent:   parent,
	}
	if parent != nil && parent.remainderFlag != nil {
		r.remainderFlag = parent.remainderFlag
	}
	var i int
	for i = 0; i < structValue.Type().NumField(); i++ {
		if StartsWithLowercase(structValue.Type().Field(i).Name) {
			continue
		}
		fieldValue := structValue.Field(i)
		tag := structValue.Type().Field(i).Tag.Get("goptions")
		flag, err := parseStructField(fieldValue, tag)
		if err != nil {
			panic(fmt.Sprintf("Invalid struct field: %s", err))
		}
		if fieldValue.Type().Name() == "Verbs" {
			r.verbFlag = flag
			break
		}
		if fieldValue.Type().Name() == "Help" {
			r.helpFlag = flag
		}
		if fieldValue.Type().Name() == "Remainder" && r.remainderFlag == nil {
			r.remainderFlag = flag
		}
		if len(tag) != 0 {
			r.Flags = append(r.Flags, flag)
		}
	}
	for i++; i < structValue.Type().NumField(); i++ {
		once.Do(func() {
			r.Verbs = make(map[string]*FlagSet)
		})
		fieldValue := structValue.Field(i)
		tag := structValue.Type().Field(i).Tag.Get("goptions")
		r.Verbs[tag] = newFlagset(tag, fieldValue, r)
	}
	r.createMaps()
	return r
}
var (
	ErrHelpRequest = errors.New("Request for Help")
)