TimestampFlag.ValueFromContext() as convenient accessor

This commit is contained in:
Tilo Prütz
2022-04-22 17:07:12 +02:00
parent 6b336c478f
commit 889c7b5d7a
2 changed files with 14 additions and 0 deletions

View File

@@ -164,6 +164,11 @@ func (f *TimestampFlag) Apply(set *flag.FlagSet) error {
return nil
}
// ValueFromContext returns the flags value in the given Context.
func (f *TimestampFlag) ValueFromContext(ctx *Context) *time.Time {
return ctx.Timestamp(f.Name)
}
// Timestamp gets the timestamp from a flag name
func (c *Context) Timestamp(name string) *time.Time {
if fs := c.lookupFlagSet(name); fs != nil {