Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate RequiredFlag and VisibleFlag implementations #1393

Merged
merged 1 commit into from May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 0 additions & 10 deletions flag_bool.go
Expand Up @@ -6,11 +6,6 @@ import (
"strconv"
)

// IsRequired returns whether or not the flag is required
func (f *BoolFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *BoolFlag) TakesValue() bool {
return false
Expand All @@ -27,11 +22,6 @@ func (f *BoolFlag) GetValue() string {
return ""
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *BoolFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *BoolFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_duration.go
Expand Up @@ -6,11 +6,6 @@ import (
"time"
)

// IsRequired returns whether or not the flag is required
func (f *DurationFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *DurationFlag) TakesValue() bool {
return true
Expand All @@ -27,11 +22,6 @@ func (f *DurationFlag) GetValue() string {
return f.Value.String()
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *DurationFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *DurationFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_float64.go
Expand Up @@ -6,11 +6,6 @@ import (
"strconv"
)

// IsRequired returns whether or not the flag is required
func (f *Float64Flag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *Float64Flag) TakesValue() bool {
return true
Expand Down Expand Up @@ -40,11 +35,6 @@ func (f *Float64Flag) GetEnvVars() []string {
return f.EnvVars
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *Float64Flag) IsVisible() bool {
return !f.Hidden
}

// Apply populates the flag given the flag set and environment
func (f *Float64Flag) Apply(set *flag.FlagSet) error {
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
Expand Down
10 changes: 0 additions & 10 deletions flag_float64_slice.go
Expand Up @@ -81,11 +81,6 @@ func (f *Float64SliceFlag) String() string {
return withEnvHint(f.GetEnvVars(), stringifyFloat64SliceFlag(f))
}

// IsRequired returns whether or not the flag is required
func (f *Float64SliceFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true if the flag takes a value, otherwise false
func (f *Float64SliceFlag) TakesValue() bool {
return true
Expand All @@ -105,11 +100,6 @@ func (f *Float64SliceFlag) GetValue() string {
return ""
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *Float64SliceFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *Float64SliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_generic.go
Expand Up @@ -11,11 +11,6 @@ type Generic interface {
String() string
}

// IsRequired returns whether or not the flag is required
func (f *GenericFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *GenericFlag) TakesValue() bool {
return true
Expand All @@ -35,11 +30,6 @@ func (f *GenericFlag) GetValue() string {
return ""
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *GenericFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *GenericFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_int.go
Expand Up @@ -6,11 +6,6 @@ import (
"strconv"
)

// IsRequired returns whether or not the flag is required
func (f *IntFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *IntFlag) TakesValue() bool {
return true
Expand All @@ -27,11 +22,6 @@ func (f *IntFlag) GetValue() string {
return fmt.Sprintf("%d", f.Value)
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *IntFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *IntFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_int64.go
Expand Up @@ -6,11 +6,6 @@ import (
"strconv"
)

// IsRequired returns whether or not the flag is required
func (f *Int64Flag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *Int64Flag) TakesValue() bool {
return true
Expand All @@ -27,11 +22,6 @@ func (f *Int64Flag) GetValue() string {
return fmt.Sprintf("%d", f.Value)
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *Int64Flag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *Int64Flag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_int64_slice.go
Expand Up @@ -82,11 +82,6 @@ func (f *Int64SliceFlag) String() string {
return withEnvHint(f.GetEnvVars(), stringifyInt64SliceFlag(f))
}

// IsRequired returns whether or not the flag is required
func (f *Int64SliceFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *Int64SliceFlag) TakesValue() bool {
return true
Expand All @@ -106,11 +101,6 @@ func (f *Int64SliceFlag) GetValue() string {
return ""
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *Int64SliceFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *Int64SliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_int_slice.go
Expand Up @@ -93,11 +93,6 @@ func (f *IntSliceFlag) String() string {
return withEnvHint(f.GetEnvVars(), stringifyIntSliceFlag(f))
}

// IsRequired returns whether or not the flag is required
func (f *IntSliceFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *IntSliceFlag) TakesValue() bool {
return true
Expand All @@ -117,11 +112,6 @@ func (f *IntSliceFlag) GetValue() string {
return ""
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *IntSliceFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *IntSliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_path.go
Expand Up @@ -7,11 +7,6 @@ import (

type Path = string

// IsRequired returns whether or not the flag is required
func (f *PathFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *PathFlag) TakesValue() bool {
return true
Expand All @@ -28,11 +23,6 @@ func (f *PathFlag) GetValue() string {
return f.Value
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *PathFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *PathFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_string.go
Expand Up @@ -5,11 +5,6 @@ import (
"fmt"
)

// IsRequired returns whether or not the flag is required
func (f *StringFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *StringFlag) TakesValue() bool {
return true
Expand All @@ -26,11 +21,6 @@ func (f *StringFlag) GetValue() string {
return f.Value
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *StringFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *StringFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_string_slice.go
Expand Up @@ -76,11 +76,6 @@ func (f *StringSliceFlag) String() string {
return withEnvHint(f.GetEnvVars(), stringifyStringSliceFlag(f))
}

// IsRequired returns whether or not the flag is required
func (f *StringSliceFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *StringSliceFlag) TakesValue() bool {
return true
Expand All @@ -100,11 +95,6 @@ func (f *StringSliceFlag) GetValue() string {
return ""
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *StringSliceFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *StringSliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_timestamp.go
Expand Up @@ -58,11 +58,6 @@ func (t *Timestamp) Get() interface{} {
return *t
}

// IsRequired returns whether or not the flag is required
func (f *TimestampFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *TimestampFlag) TakesValue() bool {
return true
Expand All @@ -82,11 +77,6 @@ func (f *TimestampFlag) GetValue() string {
return ""
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *TimestampFlag) IsVisible() bool {
return !f.Hidden
}

// GetDefaultText returns the default text for this flag
func (f *TimestampFlag) GetDefaultText() string {
if f.DefaultText != "" {
Expand Down
10 changes: 0 additions & 10 deletions flag_uint.go
Expand Up @@ -6,11 +6,6 @@ import (
"strconv"
)

// IsRequired returns whether or not the flag is required
func (f *UintFlag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *UintFlag) TakesValue() bool {
return true
Expand All @@ -21,11 +16,6 @@ func (f *UintFlag) GetUsage() string {
return f.Usage
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *UintFlag) IsVisible() bool {
return !f.Hidden
}

// Apply populates the flag given the flag set and environment
func (f *UintFlag) Apply(set *flag.FlagSet) error {
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
Expand Down
10 changes: 0 additions & 10 deletions flag_uint64.go
Expand Up @@ -6,11 +6,6 @@ import (
"strconv"
)

// IsRequired returns whether or not the flag is required
func (f *Uint64Flag) IsRequired() bool {
return f.Required
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *Uint64Flag) TakesValue() bool {
return true
Expand All @@ -21,11 +16,6 @@ func (f *Uint64Flag) GetUsage() string {
return f.Usage
}

// IsVisible returns true if the flag is not hidden, otherwise false
func (f *Uint64Flag) IsVisible() bool {
return !f.Hidden
}

// Apply populates the flag given the flag set and environment
func (f *Uint64Flag) Apply(set *flag.FlagSet) error {
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
Expand Down
16 changes: 15 additions & 1 deletion internal/genflags/generated.gotmpl
Expand Up @@ -31,7 +31,7 @@ type {{.TypeName}} struct {
func (f *{{.TypeName}}) String() string {
return {{$.UrfaveCLINamespace}}FlagStringer(f)
}
{{end}}
{{end}}{{/* /if .GenerateFmtStringerInterface */}}

{{if .GenerateFlagInterface}}
// IsSet returns whether or not the flag has been set through env or file
Expand All @@ -45,6 +45,20 @@ func (f *{{.TypeName}}) Names() []string {
}

{{end}}{{/* /if .GenerateFlagInterface */}}

{{if .GenerateRequiredFlagInterface}}
// IsRequired returns whether or not the flag is required
func (f *{{.TypeName}}) IsRequired() bool {
return f.Required
}
{{end}}{{/* /if .GenerateRequiredFlagInterface */}}

{{if .GenerateVisibleFlagInterface}}
// IsVisible returns true if the flag is not hidden, otherwise false
func (f *{{.TypeName}}) IsVisible() bool {
return !f.Hidden
}
{{end}}{{/* /if .GenerateVisibleFlagInterface */}}
{{end}}{{/* /range .SortedFlagTypes */}}

// vim{{/* 馃懟 */}}:ro
Expand Down