From 8db9e78e08578e4226dfe0ae9d9d01cd99304612 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 20 Apr 2019 16:49:12 -0400 Subject: [PATCH] mcfg: add WithFloat64 and WithRequiredFloat64 --- mcfg/param.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mcfg/param.go b/mcfg/param.go index d3a34b9..84c0708 100644 --- a/mcfg/param.go +++ b/mcfg/param.go @@ -133,6 +133,23 @@ func WithRequiredInt(ctx context.Context, name string, usage string) (context.Co return ctx, &i } +// WithFloat64 returns a *float64 which will be populated once Populate is run on +// the returned Context. +func WithFloat64(ctx context.Context, name string, defaultVal float64, usage string) (context.Context, *float64) { + f := defaultVal + ctx = WithParam(ctx, Param{Name: name, Usage: usage, Into: &f}) + return ctx, &f +} + +// WithRequiredFloat64 returns a *float64 which will be populated once Populate +// is run on the returned Context, and which must be supplied by a configuration +// Source. +func WithRequiredFloat64(ctx context.Context, name string, defaultVal float64, usage string) (context.Context, *float64) { + f := defaultVal + ctx = WithParam(ctx, Param{Name: name, Required: true, Usage: usage, Into: &f}) + return ctx, &f +} + // WithString returns a *string which will be populated once Populate is run on // the returned Context. func WithString(ctx context.Context, name, defaultVal, usage string) (context.Context, *string) {