Skip to content

Commit

Permalink
Un-regress from v3 porting losses
Browse files Browse the repository at this point in the history
  • Loading branch information
meatballhat committed Oct 13, 2022
1 parent 75aabac commit 85ff0c5
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 180 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ jobs:
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
run: make generate
- run: make diffcheck
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
# TODO: switch once v3 is released {{
# - if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
- if: 'false'
run: make v2diff
# }}
- if: success() && matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
GO_RUN_BUILD := go run internal/build/build.go

.PHONY: all
all: generate vet test check-binary-size gfmrun yamlfmt v2diff
all: generate vet test check-binary-size gfmrun yamlfmt

# NOTE: this is a special catch-all rule to run any of the commands
# defined in internal/build/build.go with optional arguments passed
Expand Down
4 changes: 2 additions & 2 deletions cmd/urfave-cli-genflags/generated_test.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func Test{{.TypeName}}_SatisfiesFlagInterface(t *testing.T) {
}

func Test{{.TypeName}}_SatisfiesRequiredFlagInterface(t *testing.T) {
var f {{$.UrfaveCLITestNamespace}}Flag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}
var f {{$.UrfaveCLITestNamespace}}RequiredFlag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}

_ = f.IsRequired()
}

func Test{{.TypeName}}_SatisfiesVisibleFlagInterface(t *testing.T) {
var f {{$.UrfaveCLITestNamespace}}Flag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}
var f {{$.UrfaveCLITestNamespace}}VisibleFlag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}

_ = f.IsVisible()
}
Expand Down
8 changes: 8 additions & 0 deletions flag_duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ func (f *DurationFlag) GetValue() string {
return f.Value.String()
}

// GetDefaultText returns the default text for this flag
func (f *DurationFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Apply populates the flag given the flag set and environment
func (f *DurationFlag) Apply(set *flag.FlagSet) error {
if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
Expand Down
8 changes: 8 additions & 0 deletions flag_float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ func (f *Float64Flag) GetValue() string {
return fmt.Sprintf("%v", f.Value)
}

// GetDefaultText returns the default text for this flag
func (f *Float64Flag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Apply populates the flag given the flag set and environment
func (f *Float64Flag) Apply(set *flag.FlagSet) error {
if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
Expand Down
8 changes: 8 additions & 0 deletions flag_float64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ func (f *Float64SliceFlag) GetValue() string {
return strings.Join(defaultVals, ", ")
}

// GetDefaultText returns the default text for this flag
func (f *Float64SliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// IsSliceFlag implements DocGenerationSliceFlag.
func (f *Float64SliceFlag) IsSliceFlag() bool {
return true
Expand Down
8 changes: 8 additions & 0 deletions flag_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func (f *GenericFlag) GetValue() string {
return ""
}

// GetDefaultText returns the default text for this flag
func (f *GenericFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Apply takes the flagset and calls Set on the generic flag with the value
// provided by the user for parsing by the flag
func (f *GenericFlag) Apply(set *flag.FlagSet) error {
Expand Down
8 changes: 8 additions & 0 deletions flag_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ func (f *IntFlag) GetValue() string {
return fmt.Sprintf("%d", f.Value)
}

// GetDefaultText returns the default text for this flag
func (f *IntFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Apply populates the flag given the flag set and environment
func (f *IntFlag) Apply(set *flag.FlagSet) error {
if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
Expand Down
8 changes: 8 additions & 0 deletions flag_int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ func (f *Int64Flag) GetValue() string {
return fmt.Sprintf("%d", f.Value)
}

// GetDefaultText returns the default text for this flag
func (f *Int64Flag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Apply populates the flag given the flag set and environment
func (f *Int64Flag) Apply(set *flag.FlagSet) error {
if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
Expand Down
8 changes: 8 additions & 0 deletions flag_int64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ func (f *Int64SliceFlag) GetValue() string {
return strings.Join(defaultVals, ", ")
}

// GetDefaultText returns the default text for this flag
func (f *Int64SliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// IsSliceFlag implements DocGenerationSliceFlag.
func (f *Int64SliceFlag) IsSliceFlag() bool {
return true
Expand Down
8 changes: 8 additions & 0 deletions flag_int_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ func (f *IntSliceFlag) GetValue() string {
return strings.Join(defaultVals, ", ")
}

// GetDefaultText returns the default text for this flag
func (f *IntSliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// IsSliceFlag implements DocGenerationSliceFlag.
func (f *IntSliceFlag) IsSliceFlag() bool {
return true
Expand Down
8 changes: 8 additions & 0 deletions flag_string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func (f *StringSliceFlag) GetValue() string {
return strings.Join(defaultVals, ", ")
}

// GetDefaultText returns the default text for this flag
func (f *StringSliceFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// IsSliceFlag implements DocGenerationSliceFlag.
func (f *StringSliceFlag) IsSliceFlag() bool {
return true
Expand Down
2 changes: 1 addition & 1 deletion flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestFlagsFromEnv(t *testing.T) {

f, ok := test.flag.(DocGenerationFlag)
if !ok {
t.Errorf("flag %v needs to implement DocGenerationFlag to retrieve env vars", test.flag)
t.Errorf("flag %[1]q (%[1]T) needs to implement DocGenerationFlag to retrieve env vars", test.flag)
}
envVarSlice := f.GetEnvVars()
_ = os.Setenv(envVarSlice[0], test.input)
Expand Down
8 changes: 8 additions & 0 deletions flag_timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func (f *TimestampFlag) GetValue() string {
return ""
}

// GetDefaultText returns the default text for this flag
func (f *TimestampFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Apply populates the flag given the flag set and environment
func (f *TimestampFlag) Apply(set *flag.FlagSet) error {
if f.Layout == "" {
Expand Down
8 changes: 8 additions & 0 deletions flag_uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func (f *UintFlag) GetValue() string {
return fmt.Sprintf("%d", f.Value)
}

// GetDefaultText returns the default text for this flag
func (f *UintFlag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Get returns the flag’s value in the given Context.
func (f *UintFlag) Get(ctx *Context) uint {
return ctx.Uint(f.Name)
Expand Down
8 changes: 8 additions & 0 deletions flag_uint64.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func (f *Uint64Flag) GetValue() string {
return fmt.Sprintf("%d", f.Value)
}

// GetDefaultText returns the default text for this flag
func (f *Uint64Flag) GetDefaultText() string {
if f.DefaultText != "" {
return f.DefaultText
}
return f.GetValue()
}

// Get returns the flag’s value in the given Context.
func (f *Uint64Flag) Get(ctx *Context) uint64 {
return ctx.Uint64(f.Name)
Expand Down
20 changes: 0 additions & 20 deletions flag_uint64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,6 @@ func (f *Uint64SliceFlag) String() string {
return FlagStringer(f)
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *Uint64SliceFlag) TakesValue() bool {
return true
}

// GetUsage returns the usage string for the flag
func (f *Uint64SliceFlag) GetUsage() string {
return f.Usage
}

// GetCategory returns the category for the flag
func (f *Uint64SliceFlag) GetCategory() string {
return f.Category
}

// GetValue returns the flags value as string representation and an empty
// string if the flag takes no value at all.
func (f *Uint64SliceFlag) GetValue() string {
Expand All @@ -126,11 +111,6 @@ func (f *Uint64SliceFlag) GetDefaultText() string {
return f.GetValue()
}

// GetEnvVars returns the env vars for this flag
func (f *Uint64SliceFlag) GetEnvVars() []string {
return f.EnvVars
}

// IsSliceFlag implements DocGenerationSliceFlag.
func (f *Uint64SliceFlag) IsSliceFlag() bool {
return true
Expand Down
20 changes: 0 additions & 20 deletions flag_uint_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,6 @@ func (f *UintSliceFlag) String() string {
return FlagStringer(f)
}

// TakesValue returns true of the flag takes a value, otherwise false
func (f *UintSliceFlag) TakesValue() bool {
return true
}

// GetUsage returns the usage string for the flag
func (f *UintSliceFlag) GetUsage() string {
return f.Usage
}

// GetCategory returns the category for the flag
func (f *UintSliceFlag) GetCategory() string {
return f.Category
}

// GetValue returns the flags value as string representation and an empty
// string if the flag takes no value at all.
func (f *UintSliceFlag) GetValue() string {
Expand All @@ -137,11 +122,6 @@ func (f *UintSliceFlag) GetDefaultText() string {
return f.GetValue()
}

// GetEnvVars returns the env vars for this flag
func (f *UintSliceFlag) GetEnvVars() []string {
return f.EnvVars
}

// IsSliceFlag implements DocGenerationSliceFlag.
func (f *UintSliceFlag) IsSliceFlag() bool {
return true
Expand Down

0 comments on commit 85ff0c5

Please sign in to comment.