Skip to content

Commit

Permalink
rename flags’ ValueFromContext() to Get()
Browse files Browse the repository at this point in the history
  • Loading branch information
toaster committed Apr 25, 2022
1 parent ca7f26e commit 835bd32
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions flag_bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (f *BoolFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *BoolFlag) ValueFromContext(ctx *Context) bool {
// Get returns the flag’s value in the given Context.
func (f *BoolFlag) Get(ctx *Context) bool {
return ctx.Bool(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (f *DurationFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *DurationFlag) ValueFromContext(ctx *Context) time.Duration {
// Get returns the flag’s value in the given Context.
func (f *DurationFlag) Get(ctx *Context) time.Duration {
return ctx.Duration(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (f *Float64Flag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *Float64Flag) ValueFromContext(ctx *Context) float64 {
// Get returns the flag’s value in the given Context.
func (f *Float64Flag) Get(ctx *Context) float64 {
return ctx.Float64(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_float64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *Float64SliceFlag) ValueFromContext(ctx *Context) []float64 {
// Get returns the flag’s value in the given Context.
func (f *Float64SliceFlag) Get(ctx *Context) []float64 {
return ctx.Float64Slice(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func (f GenericFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *GenericFlag) ValueFromContext(ctx *Context) interface{} {
// Get returns the flag’s value in the given Context.
func (f *GenericFlag) Get(ctx *Context) interface{} {
return ctx.Generic(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (f *IntFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *IntFlag) ValueFromContext(ctx *Context) int {
// Get returns the flag’s value in the given Context.
func (f *IntFlag) Get(ctx *Context) int {
return ctx.Int(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (f *Int64Flag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *Int64Flag) ValueFromContext(ctx *Context) int64 {
// Get returns the flag’s value in the given Context.
func (f *Int64Flag) Get(ctx *Context) int64 {
return ctx.Int64(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_int64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *Int64SliceFlag) ValueFromContext(ctx *Context) []int64 {
// Get returns the flag’s value in the given Context.
func (f *Int64SliceFlag) Get(ctx *Context) []int64 {
return ctx.Int64Slice(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_int_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *IntSliceFlag) ValueFromContext(ctx *Context) []int {
// Get returns the flag’s value in the given Context.
func (f *IntSliceFlag) Get(ctx *Context) []int {
return ctx.IntSlice(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (f *PathFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *PathFlag) ValueFromContext(ctx *Context) string {
// Get returns the flag’s value in the given Context.
func (f *PathFlag) Get(ctx *Context) string {
return ctx.Path(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func (f *StringFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *StringFlag) ValueFromContext(ctx *Context) string {
// Get returns the flag’s value in the given Context.
func (f *StringFlag) Get(ctx *Context) string {
return ctx.String(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *StringSliceFlag) ValueFromContext(ctx *Context) []string {
// Get returns the flag’s value in the given Context.
func (f *StringSliceFlag) Get(ctx *Context) []string {
return ctx.StringSlice(f.Name)
}

Expand Down
32 changes: 16 additions & 16 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestBoolFlagValueFromContext(t *testing.T) {
ctx := NewContext(nil, set, nil)
tf := &BoolFlag{Name: "trueflag"}
ff := &BoolFlag{Name: "falseflag"}
expect(t, tf.ValueFromContext(ctx), true)
expect(t, ff.ValueFromContext(ctx), false)
expect(t, tf.Get(ctx), true)
expect(t, ff.Get(ctx), false)
}

func TestFlagsFromEnv(t *testing.T) {
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestStringFlagValueFromContext(t *testing.T) {
set.String("myflag", "foobar", "doc")
ctx := NewContext(nil, set, nil)
f := &StringFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), "foobar")
expect(t, f.Get(ctx), "foobar")
}

var pathFlagTests = []struct {
Expand Down Expand Up @@ -514,7 +514,7 @@ func TestPathFlagValueFromContext(t *testing.T) {
set.String("myflag", "/my/path", "doc")
ctx := NewContext(nil, set, nil)
f := &PathFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), "/my/path")
expect(t, f.Get(ctx), "/my/path")
}

var envHintFlagTests = []struct {
Expand Down Expand Up @@ -635,7 +635,7 @@ func TestStringSliceFlagValueFromContext(t *testing.T) {
set.Var(NewStringSlice("a", "b", "c"), "myflag", "doc")
ctx := NewContext(nil, set, nil)
f := &StringSliceFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), []string{"a", "b", "c"})
expect(t, f.Get(ctx), []string{"a", "b", "c"})
}

var intFlagTests = []struct {
Expand Down Expand Up @@ -692,7 +692,7 @@ func TestIntFlagValueFromContext(t *testing.T) {
set.Int("myflag", 42, "doc")
ctx := NewContext(nil, set, nil)
f := &IntFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), 42)
expect(t, f.Get(ctx), 42)
}

var int64FlagTests = []struct {
Expand Down Expand Up @@ -738,7 +738,7 @@ func TestInt64FlagValueFromContext(t *testing.T) {
set.Int64("myflag", 42, "doc")
ctx := NewContext(nil, set, nil)
f := &Int64Flag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), int64(42))
expect(t, f.Get(ctx), int64(42))
}

var uintFlagTests = []struct {
Expand Down Expand Up @@ -784,7 +784,7 @@ func TestUintFlagValueFromContext(t *testing.T) {
set.Uint("myflag", 42, "doc")
ctx := NewContext(nil, set, nil)
f := &UintFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), uint(42))
expect(t, f.Get(ctx), uint(42))
}

var uint64FlagTests = []struct {
Expand Down Expand Up @@ -830,7 +830,7 @@ func TestUint64FlagValueFromContext(t *testing.T) {
set.Uint64("myflag", 42, "doc")
ctx := NewContext(nil, set, nil)
f := &Uint64Flag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), uint64(42))
expect(t, f.Get(ctx), uint64(42))
}

var durationFlagTests = []struct {
Expand Down Expand Up @@ -887,7 +887,7 @@ func TestDurationFlagValueFromContext(t *testing.T) {
set.Duration("myflag", 42*time.Second, "doc")
ctx := NewContext(nil, set, nil)
f := &DurationFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), 42*time.Second)
expect(t, f.Get(ctx), 42*time.Second)
}

var intSliceFlagTests = []struct {
Expand Down Expand Up @@ -984,7 +984,7 @@ func TestIntSliceFlagValueFromContext(t *testing.T) {
set.Var(NewIntSlice(1, 2, 3), "myflag", "doc")
ctx := NewContext(nil, set, nil)
f := &IntSliceFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), []int{1, 2, 3})
expect(t, f.Get(ctx), []int{1, 2, 3})
}

var int64SliceFlagTests = []struct {
Expand Down Expand Up @@ -1088,7 +1088,7 @@ func TestInt64SliceFlagValueFromContext(t *testing.T) {
set.Var(NewInt64Slice(1, 2, 3), "myflag", "doc")
ctx := NewContext(nil, set, nil)
f := &Int64SliceFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), []int64{1, 2, 3})
expect(t, f.Get(ctx), []int64{1, 2, 3})
}

var float64FlagTests = []struct {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ func TestFloat64FlagValueFromContext(t *testing.T) {
set.Float64("myflag", 1.23, "doc")
ctx := NewContext(nil, set, nil)
f := &Float64Flag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), 1.23)
expect(t, f.Get(ctx), 1.23)
}

var float64SliceFlagTests = []struct {
Expand Down Expand Up @@ -1194,7 +1194,7 @@ func TestFloat64SliceFlagValueFromContext(t *testing.T) {
set.Var(NewFloat64Slice(1.23, 4.56), "myflag", "doc")
ctx := NewContext(nil, set, nil)
f := &Float64SliceFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), []float64{1.23, 4.56})
expect(t, f.Get(ctx), []float64{1.23, 4.56})
}

var genericFlagTests = []struct {
Expand Down Expand Up @@ -1250,7 +1250,7 @@ func TestGenericFlagValueFromContext(t *testing.T) {
set.Var(&Parser{"abc", "def"}, "myflag", "doc")
ctx := NewContext(nil, set, nil)
f := &GenericFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), &Parser{"abc", "def"})
expect(t, f.Get(ctx), &Parser{"abc", "def"})
}

func TestParseMultiString(t *testing.T) {
Expand Down Expand Up @@ -2286,7 +2286,7 @@ func TestTimestampFlagValueFromContext(t *testing.T) {
set.Var(NewTimestamp(now), "myflag", "doc")
ctx := NewContext(nil, set, nil)
f := &TimestampFlag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), &now)
expect(t, f.Get(ctx), &now)
}

type flagDefaultTestCase struct {
Expand Down
4 changes: 2 additions & 2 deletions flag_timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ func (f *TimestampFlag) Apply(set *flag.FlagSet) error {
return nil
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *TimestampFlag) ValueFromContext(ctx *Context) *time.Time {
// Get returns the flag’s value in the given Context.
func (f *TimestampFlag) Get(ctx *Context) *time.Time {
return ctx.Timestamp(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (f *UintFlag) GetEnvVars() []string {
return f.EnvVars
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *UintFlag) ValueFromContext(ctx *Context) uint {
// Get returns the flag’s value in the given Context.
func (f *UintFlag) Get(ctx *Context) uint {
return ctx.Uint(f.Name)
}

Expand Down
4 changes: 2 additions & 2 deletions flag_uint64.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (f *Uint64Flag) GetEnvVars() []string {
return f.EnvVars
}

// ValueFromContext returns the flag’s value in the given Context.
func (f *Uint64Flag) ValueFromContext(ctx *Context) uint64 {
// Get returns the flag’s value in the given Context.
func (f *Uint64Flag) Get(ctx *Context) uint64 {
return ctx.Uint64(f.Name)
}

Expand Down

0 comments on commit 835bd32

Please sign in to comment.