rename flags’ ValueFromContext() to Get()
This commit is contained in:
parent
ca7f26ecb0
commit
835bd32714
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
32
flag_test.go
32
flag_test.go
@ -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) {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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) {
|
||||
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user