func (f *PathFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVars != nil {
		for _, envVar := range f.EnvVars {
			if envVal, ok := syscall.Getenv(envVar); ok {
				f.Value = envVal
				break
			}
		}
	}
	for _, name := range f.Names() {
		if f.Destination != nil {
			set.StringVar(f.Destination, name, f.Value, f.Usage)
			continue
		}
		set.String(name, f.Value, f.Usage)
	}
	return nil
}
ApplyWithError populates the flag given the flag set and environment
package cli
import (
	"encoding/json"
	"flag"
	"fmt"
	"reflect"
	"regexp"
	"runtime"
	"strconv"
	"strings"
	"syscall"
	"time"
)
const defaultPlaceholder = "value"
var (
	slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano())
	commaWhitespace = regexp.MustCompile("[, ]+.*")
)
var GenerateCompletionFlag Flag = &BoolFlag{
	Name:   "generate-completion",
	Hidden: true,
}
func genCompName() string {
	names := GenerateCompletionFlag.Names()
	if len(names) == 0 {
		return "generate-completion"
	}
	return names[0]
}
var InitCompletionFlag = &StringFlag{
	Name:  "init-completion",
	Usage: "generate completion code. Value must be 'bash' or 'zsh'",
}
var VersionFlag Flag = &BoolFlag{
	Name:    "version",
	Aliases: []string{"v"},
	Usage:   "print the version",
}
var HelpFlag Flag = &BoolFlag{
	Name:    "help",
	Aliases: []string{"h"},
	Usage:   "show help",
}
var FlagStringer FlagStringFunc = stringifyFlag
type Serializeder interface {
	Serialized() string
}
type FlagsByName []Flag
func (f FlagsByName) Len() int {
	return len(f)
}
func (f FlagsByName) Less(i, j int) bool {
	if len(f[j].Names()) == 0 {
		return false
	} else if len(f[i].Names()) == 0 {
		return true
	}
	return f[i].Names()[0] < f[j].Names()[0]
}
func (f FlagsByName) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}
type Flag interface {
	fmt.Stringer
	Apply(*flag.FlagSet)
	Names() []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
}
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.EnvVars != nil {
		for _, envVar := range f.EnvVars {
			if envVal, ok := syscall.Getenv(envVar); ok {
				val.Set(envVal)
				break
			}
		}
	}
	for _, name := range f.Names() {
		set.Var(val, name, f.Usage)
	}
	return nil
}
type StringSlice struct {
	slice      []string
	hasBeenSet bool
}
func NewStringSlice(defaults ...string) *StringSlice {
	return &StringSlice{slice: append([]string{}, defaults...)}
}
func (f *StringSlice) Set(value string) error {
	if !f.hasBeenSet {
		f.slice = []string{}
		f.hasBeenSet = true
	}
	if strings.HasPrefix(value, slPfx) {
		_ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &f.slice)
		f.hasBeenSet = true
		return nil
	}
	f.slice = append(f.slice, value)
	return nil
}
func (f *StringSlice) String() string {
	return fmt.Sprintf("%s", f.slice)
}
func (f *StringSlice) Serialized() string {
	jsonBytes, _ := json.Marshal(f.slice)
	return fmt.Sprintf("%s%s", slPfx, string(jsonBytes))
}
func (f *StringSlice) Value() []string {
	return f.slice
}
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.EnvVars != nil {
		for _, envVar := range f.EnvVars {
			if envVal, ok := syscall.Getenv(envVar); ok {
				newVal := NewStringSlice()
				for _, s := range strings.Split(envVal, ",") {
					s = strings.TrimSpace(s)
					if err := newVal.Set(s); err != nil {
						return fmt.Errorf("could not parse %q as string value for flag %s: %s", envVal, f.Name, err)
					}
				}
				f.Value = newVal
				break
			}
		}
	}
	if f.Value == nil {
		f.Value = NewStringSlice()
	}
	for _, name := range f.Names() {
		set.Var(f.Value, name, f.Usage)
	}
	return nil
}
type IntSlice struct {
	slice      []int
	hasBeenSet bool
}
func NewIntSlice(defaults ...int) *IntSlice {
	return &IntSlice{slice: append([]int{}, defaults...)}
}
func NewInt64Slice(defaults ...int64) *Int64Slice {
	return &Int64Slice{slice: append([]int64{}, defaults...)}
}
func (i *IntSlice) SetInt(value int) {
	if !i.hasBeenSet {
		i.slice = []int{}
		i.hasBeenSet = true
	}
	i.slice = append(i.slice, value)
}
func (i *IntSlice) Set(value string) error {
	if !i.hasBeenSet {
		i.slice = []int{}
		i.hasBeenSet = true
	}
	if strings.HasPrefix(value, slPfx) {
		_ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &i.slice)
		i.hasBeenSet = true
		return nil
	}
	tmp, err := strconv.ParseInt(value, 0, 64)
	if err != nil {
		return err
	}
	i.slice = append(i.slice, int(tmp))
	return nil
}
func (f *IntSlice) String() string {
	return fmt.Sprintf("%#v", f.slice)
}
func (i *IntSlice) Serialized() string {
	jsonBytes, _ := json.Marshal(i.slice)
	return fmt.Sprintf("%s%s", slPfx, string(jsonBytes))
}
func (i *IntSlice) Value() []int {
	return i.slice
}
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.EnvVars != nil {
		for _, envVar := range f.EnvVars {
			if envVal, ok := syscall.Getenv(envVar); ok {
				newVal := NewIntSlice()
				for _, s := range strings.Split(envVal, ",") {
					s = strings.TrimSpace(s)
					if err := newVal.Set(s); err != nil {
						return fmt.Errorf("could not parse %q as int slice value for flag %s: %s", envVal, f.Name, err)
					}
				}
				f.Value = newVal
				break
			}
		}
	}
	if f.Value == nil {
		f.Value = NewIntSlice()
	}
	for _, name := range f.Names() {
		set.Var(f.Value, name, f.Usage)
	}
	return nil
}
type Int64Slice struct {
	slice      []int64
	hasBeenSet bool
}
func (f *Int64Slice) Set(value string) error {
	if !f.hasBeenSet {
		f.slice = []int64{}
		f.hasBeenSet = true
	}
	if strings.HasPrefix(value, slPfx) {
		_ = json.Unmarshal([]byte(strings.Replace(value, slPfx, "", 1)), &f.slice)
		f.hasBeenSet = true
		return nil
	}
	tmp, err := strconv.ParseInt(value, 0, 64)
	if err != nil {
		return err
	}
	f.slice = append(f.slice, tmp)
	return nil
}
func (f *Int64Slice) String() string {
	return fmt.Sprintf("%#v", f.slice)
}
func (f *Int64Slice) Serialized() string {
	jsonBytes, _ := json.Marshal(f.slice)
	return fmt.Sprintf("%s%s", slPfx, string(jsonBytes))
}
func (f *Int64Slice) Value() []int64 {
	return f.slice
}
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.EnvVars != nil {
		for _, envVar := range f.EnvVars {
			if envVal, ok := syscall.Getenv(envVar); ok {
				newVal := NewInt64Slice()
				for _, s := range strings.Split(envVal, ",") {
					s = strings.TrimSpace(s)
					if err := newVal.Set(s); err != nil {
						return fmt.Errorf("could not parse %q as int64 slice value for flag %s: %s", envVal, f.Name, err)
					}
				}
				f.Value = newVal
				break
			}
		}
	}
	if f.Value == nil {
		f.Value = NewInt64Slice()
	}
	for _, name := range f.Names() {
		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 {
	if f.EnvVars != nil {
		for _, envVar := range f.EnvVars {
			if envVal, ok := syscall.Getenv(envVar); ok {
				if envVal == "" {
					f.Value = false
					break
				}
				envValBool, err := strconv.ParseBool(envVal)
				if err != nil {
					return fmt.Errorf("could not parse %q as bool value for flag %s: %s", envVal, f.Name, err)
				}
				f.Value = envValBool
				break
			}
		}
	}
	for _, name := range f.Names() {
		if f.Destination != nil {
			set.BoolVar(f.Destination, name, f.Value, f.Usage)
			continue
		}
		set.Bool(name, f.Value, f.Usage)
	}
	return nil
}
func (f *StringFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}
func (f *StringFlag) ApplyWithError(set *flag.FlagSet) error {
	if f.EnvVars != nil {
		for _, envVar := range f.EnvVars {
			if envVal, ok := syscall.Getenv(envVar); ok {
				f.Value = envVal
				break
			}
		}
	}
	for _, name := range f.Names() {
		if f.Destination != nil {
			set.StringVar(f.Destination, name, f.Value, f.Usage)
			continue
		}
		set.String(name, f.Value, f.Usage)
	}
	return nil
}
func (f *PathFlag) Apply(set *flag.FlagSet) {
	f.ApplyWithError(set)
}