Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time flags #129

Merged
merged 1 commit into from
May 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,41 @@ func (f *FlagSection) StringSliceVar(i *StringSliceVar) {
})
}

type TimeVar struct {
Name string
Aliases []string
Usage string
Example string
Default time.Time
Hidden bool
EnvVar string
Predict complete.Predictor
Target *time.Time
}

func (f *FlagSection) TimeVar(layout string, i *TimeVar) {
parser := func(s string) (time.Time, error) {
return time.Parse(layout, s)
}
printer := func(v time.Time) string {
return v.Format(layout)
}

Flag(f, &Var[time.Time]{
Name: i.Name,
Aliases: i.Aliases,
Usage: i.Usage,
Example: i.Example,
Default: i.Default,
Hidden: i.Hidden,
EnvVar: i.EnvVar,
Predict: i.Predict,
Target: i.Target,
Parser: parser,
Printer: printer,
})
}

type UintVar struct {
Name string
Aliases []string
Expand Down