2019-08-04 04:35:44 +00:00
|
|
|
// Code generated by fg; DO NOT EDIT.
|
|
|
|
|
|
|
|
package {{ .PackageName }}
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2019-08-03 10:41:50 +00:00
|
|
|
"fmt"
|
2019-08-04 04:35:44 +00:00
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
{{ range $i, $flag := .Flags }}
|
|
|
|
// {{ $flag.Name }}Flag is a flag with type {{ $flag.Type }}{{ $flag.Doctail }}
|
|
|
|
type {{ $flag.Name }}Flag struct {
|
2019-08-04 14:59:53 +00:00
|
|
|
Name string
|
2019-08-04 14:53:32 +00:00
|
|
|
Usage string
|
|
|
|
EnvVar string
|
|
|
|
FilePath string
|
|
|
|
Required bool
|
|
|
|
Hidden bool
|
2019-08-09 07:05:55 +00:00
|
|
|
TakesFile bool
|
2019-08-04 14:53:32 +00:00
|
|
|
{{- if eq $flag.Value true }}
|
|
|
|
Value {{ $flag.Type }}
|
2019-08-04 04:35:44 +00:00
|
|
|
{{- end }}
|
|
|
|
{{- if eq $flag.Destination true }}
|
|
|
|
Destination *{{ $flag.Type }}
|
|
|
|
{{- end }}
|
|
|
|
}
|
|
|
|
|
|
|
|
// String returns a readable representation of this value
|
|
|
|
// (for usage defaults)
|
|
|
|
func (f {{ $flag.Name }}Flag) String() string {
|
2019-08-04 14:53:32 +00:00
|
|
|
return FlagStringer(f)
|
2019-08-04 04:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetName returns the name of the flag
|
|
|
|
func (f {{ $flag.Name }}Flag) GetName() string {
|
2019-08-04 14:53:32 +00:00
|
|
|
return f.Name
|
2019-08-04 04:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsRequired returns whether or not the flag is required
|
|
|
|
func (f {{ $flag.Name }}Flag) IsRequired() bool {
|
2019-08-04 14:53:32 +00:00
|
|
|
return f.Required
|
2019-08-04 04:35:44 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 10:41:50 +00:00
|
|
|
// TakesValue returns true of the flag takes a value, otherwise false
|
|
|
|
func (f {{ $flag.Name }}Flag) TakesValue() bool {
|
|
|
|
return {{ $flag.Value }}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetUsage returns the usage string for the flag
|
|
|
|
func (f {{ $flag.Name }}Flag) GetUsage() string {
|
|
|
|
return f.Usage
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetValue returns the flags value as string representation and an empty
|
|
|
|
// string if the flag takes no value at all.
|
|
|
|
func (f {{ $flag.Name }}Flag) GetValue() string {
|
|
|
|
{{ $flag.ValueString }}
|
|
|
|
}
|
|
|
|
|
2019-08-04 04:35:44 +00:00
|
|
|
// {{ $flag.Name }} looks up the value of a local {{ $flag.Name }}Flag, returns
|
|
|
|
// {{ $flag.ContextDefault }} if not found
|
2019-08-04 14:53:32 +00:00
|
|
|
func (c *Context) {{ $flag.Name }}(name string) {{ if ne .ContextType "" }}{{ $flag.ContextType }}{{ else }}{{ $flag.Type }}{{- end }} {
|
|
|
|
return lookup{{ $flag.Name }}(name, c.flagSet)
|
2019-08-04 04:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Global{{ $flag.Name }} looks up the value of a global {{ $flag.Name }}Flag, returns
|
|
|
|
// {{ $flag.ContextDefault }} if not found
|
2019-08-04 14:53:32 +00:00
|
|
|
func (c *Context) Global{{ $flag.Name }}(name string) {{ if ne .ContextType "" }}{{ $flag.ContextType }}{{ else }}{{ $flag.Type }}{{- end }} {
|
|
|
|
if fs := lookupGlobalFlagSet(name, c); fs != nil {
|
|
|
|
return lookup{{ $flag.Name }}(name, fs)
|
|
|
|
}
|
|
|
|
return {{ $flag.ContextDefault }}
|
2019-08-04 04:35:44 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 14:53:32 +00:00
|
|
|
func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextType "" }}{{ $flag.ContextType }}{{ else }}{{ $flag.Type }}{{- end }} {
|
|
|
|
f := set.Lookup(name)
|
|
|
|
if f != nil {
|
|
|
|
{{ if ne .Parser "" }}parsed, err := {{ $flag.Parser }}{{ else }}parsed, err := f.Value, error(nil){{ end }}
|
|
|
|
if err != nil {
|
|
|
|
return {{ $flag.ContextDefault }}
|
|
|
|
}
|
|
|
|
{{ if ne .ParserCast "" }}return {{ $flag.ParserCast }}{{ else }}return parsed{{ end }}
|
|
|
|
}
|
|
|
|
return {{ $flag.ContextDefault }}
|
2019-08-04 04:35:44 +00:00
|
|
|
}
|
2019-08-03 10:41:50 +00:00
|
|
|
{{ end }}
|