func (f Int64Flag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				envValInt, err := strconv.ParseInt(envVal, 0, 64)
				if err != nil {
					return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
				}
				f.Value = envValInt
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Destination != nil {
			set.Int64Var(f.Destination, name, f.Value, f.Usage)
			return
		}
		set.Int64(name, f.Value, f.Usage)
	})
	return nil
}
ApplyWithError populates the flag given the flag set and environment
package cli
import (
	"flag"
	"fmt"
	"reflect"
	"runtime"
	"strconv"
	"strings"
	"syscall"
	"time"
)
const defaultPlaceholder = "value"
var BashCompletionFlag Flag = BoolFlag{
	Name:   "generate-bash-completion",
	Hidden: true,
}
var VersionFlag Flag = BoolFlag{
	Name:  "version, v",
	Usage: "print the version",
}
var HelpFlag Flag = BoolFlag{
	Name:  "help, h",
	Usage: "show help",
}
var FlagStringer FlagStringFunc = stringifyFlag
type FlagsByName []Flag
func (f FlagsByName) Len() int {
	return len(f)
}
func (f FlagsByName) Less(i, j int) bool {
	return f[i].GetName() < f[j].GetName()
}
func (f FlagsByName) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}
type Flag interface {
	fmt.Stringer
	Apply(*flag.FlagSet)
	GetName() string
}
type errorableFlag interface {
	Flag
	ApplyWithError(*flag.FlagSet) error
}
func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
	set := flag.NewFlagSet(name, flag.ContinueOnError)
	for _, f := range flags {
		if ef, ok := f.(errorableFlag); ok {
			if err := ef.ApplyWithError(set); err != nil {
				return nil, err
			}
		} else {
			f.Apply(set)
		}
	}
	return set, nil
}
func eachName(longName string, fn func(string)) {
	parts := strings.Split(longName, ",")
	for _, name := range parts {
		name = strings.Trim(name, " ")
		fn(name)
	}
}
type Generic interface {
	Set(value string) error
	String() string
}
func (f GenericFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f GenericFlag) ApplyWithError(set *flag.FlagSet) error {
	val := f.Value
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				if err := val.Set(envVal); err != nil {
					return fmt.Errorf("could not parse %s as value for flag %s: %s", envVal, f.Name, err)
				}
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		set.Var(f.Value, name, f.Usage)
	})
	return nil
}
type StringSlice []string
func (f *StringSlice) Set(value string) error {
	*f = append(*f, value)
	return nil
}
func (f *StringSlice) String() string {
	return fmt.Sprintf("%s", *f)
}
func (f *StringSlice) Value() []string {
	return *f
}
func (f *StringSlice) Get() interface{} {
	return *f
}
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f StringSliceFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				newVal := &StringSlice{}
				for _, s := range strings.Split(envVal, ",") {
					s = strings.TrimSpace(s)
					if err := newVal.Set(s); err != nil {
						return fmt.Errorf("could not parse %s as string value for flag %s: %s", envVal, f.Name, err)
					}
				}
				f.Value = newVal
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Value == nil {
			f.Value = &StringSlice{}
		}
		set.Var(f.Value, name, f.Usage)
	})
	return nil
}
type IntSlice []int
func (f *IntSlice) Set(value string) error {
	tmp, err := strconv.Atoi(value)
	if err != nil {
		return err
	}
	*f = append(*f, tmp)
	return nil
}
func (f *IntSlice) String() string {
	return fmt.Sprintf("%#v", *f)
}
func (f *IntSlice) Value() []int {
	return *f
}
func (f *IntSlice) Get() interface{} {
	return *f
}
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f IntSliceFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				newVal := &IntSlice{}
				for _, s := range strings.Split(envVal, ",") {
					s = strings.TrimSpace(s)
					if err := newVal.Set(s); err != nil {
						return fmt.Errorf("could not parse %s as int slice value for flag %s: %s", envVal, f.Name, err)
					}
				}
				f.Value = newVal
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Value == nil {
			f.Value = &IntSlice{}
		}
		set.Var(f.Value, name, f.Usage)
	})
	return nil
}
type Int64Slice []int64
func (f *Int64Slice) Set(value string) error {
	tmp, err := strconv.ParseInt(value, 10, 64)
	if err != nil {
		return err
	}
	*f = append(*f, tmp)
	return nil
}
func (f *Int64Slice) String() string {
	return fmt.Sprintf("%#v", *f)
}
func (f *Int64Slice) Value() []int64 {
	return *f
}
func (f *Int64Slice) Get() interface{} {
	return *f
}
func (f Int64SliceFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f Int64SliceFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				newVal := &Int64Slice{}
				for _, s := range strings.Split(envVal, ",") {
					s = strings.TrimSpace(s)
					if err := newVal.Set(s); err != nil {
						return fmt.Errorf("could not parse %s as int64 slice value for flag %s: %s", envVal, f.Name, err)
					}
				}
				f.Value = newVal
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Value == nil {
			f.Value = &Int64Slice{}
		}
		set.Var(f.Value, name, f.Usage)
	})
	return nil
}
func (f BoolFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f BoolFlag) ApplyWithError(set *flag.FlagSet) error {
	val := false
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				if envVal == "" {
					val = false
					break
				}
				envValBool, err := strconv.ParseBool(envVal)
				if err != nil {
					return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
				}
				val = envValBool
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Destination != nil {
			set.BoolVar(f.Destination, name, val, f.Usage)
			return
		}
		set.Bool(name, val, f.Usage)
	})
	return nil
}
func (f BoolTFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f BoolTFlag) ApplyWithError(set *flag.FlagSet) error {
	val := true
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				if envVal == "" {
					val = false
					break
				}
				envValBool, err := strconv.ParseBool(envVal)
				if err != nil {
					return fmt.Errorf("could not parse %s as bool value for flag %s: %s", envVal, f.Name, err)
				}
				val = envValBool
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Destination != nil {
			set.BoolVar(f.Destination, name, val, f.Usage)
			return
		}
		set.Bool(name, val, f.Usage)
	})
	return nil
}
func (f StringFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f StringFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				f.Value = envVal
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Destination != nil {
			set.StringVar(f.Destination, name, f.Value, f.Usage)
			return
		}
		set.String(name, f.Value, f.Usage)
	})
	return nil
}
func (f IntFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f IntFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVar != "" {
		for _, envVar := range strings.Split(f.EnvVar, ",") {
			envVar = strings.TrimSpace(envVar)
			if envVal, ok := syscall.Getenv(envVar); ok {
				envValInt, err := strconv.ParseInt(envVal, 0, 64)
				if err != nil {
					return fmt.Errorf("could not parse %s as int value for flag %s: %s", envVal, f.Name, err)
				}
				f.Value = int(envValInt)
				break
			}
		}
	}
	eachName(f.Name, func(name string) {
		if f.Destination != nil {
			set.IntVar(f.Destination, name, f.Value, f.Usage)
			return
		}
		set.Int(name, f.Value, f.Usage)
	})
	return nil
}
func (f Int64Flag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}