Float64Flag.ValueFromContext() as convenient accessor

main
Tilo Prütz 2 years ago
parent 9eae255aac
commit 5047beb001

@ -101,6 +101,11 @@ func (f *Float64Flag) Apply(set *flag.FlagSet) error {
return nil
}
// ValueFromContext returns the flags value in the given Context.
func (f *Float64Flag) ValueFromContext(ctx *Context) float64 {
return ctx.Float64(f.Name)
}
// Float64 looks up the value of a local Float64Flag, returns
// 0 if not found
func (c *Context) Float64(name string) float64 {

@ -1068,6 +1068,14 @@ func TestFloat64FlagApply_SetsAllNames(t *testing.T) {
expect(t, v, float64(43.33333))
}
func TestFloat64FlagValueFromContext(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Float64("myflag", 1.23, "doc")
ctx := NewContext(nil, set, nil)
f := &Float64Flag{Name: "myflag"}
expect(t, f.ValueFromContext(ctx), 1.23)
}
var float64SliceFlagTests = []struct {
name string
aliases []string

Loading…
Cancel
Save