pflag icon indicating copy to clipboard operation
pflag copied to clipboard

Add support for time.Time flags

Open max-frank opened this issue 2 years ago • 8 comments

This PR implements support for time.Time flags which can be used to accept timestamps as input directly (see https://github.com/spf13/cobra/issues/742).

The implementation allows defining a list of acceptable timestamp formats which are tested in order, i.e., devs using this flag type would be responsible for ordering their formats correctly should there be an overlap.

max-frank avatar Mar 23 '22 11:03 max-frank

This is exactly what I am looking for. Would it be possible to review and merge this?

Maybe also suggestion for small improvement, would it be possible to offer some reasonable standard default ordering? Like this:

var DefaultOrdering []string = []string{time.RFC3339, time.UnixDate, ...}

or this:

func getDefaultOrdering() []string {
	return []string{time.RFC3339, time.UnixDate, ...}
}

kostrahb avatar Apr 27 '22 20:04 kostrahb

I was thinking of adding a constant slice with a suggested default time format set, but opted to not include it in this PR since its easy to define such a constant in whatever code you use and more importantly I wanted to avoid any long winded discussions on what the actual order and included formats should be.

max-frank avatar May 06 '22 04:05 max-frank

@johnSchnake tagging you (a bit late) for this PR as requested in https://github.com/spf13/cobra/issues/742

max-frank avatar Aug 21 '22 08:08 max-frank

hate being that guy...but: any news on when will this be in?

alexferrari88 avatar Jul 19 '23 10:07 alexferrari88

Yeah sadly seems that the repo is just sitting here now anymore nothing happening :/

i tried to make some noise in the related issue on the cobra side but nothing yet

max-frank avatar Jul 19 '23 11:07 max-frank

Anything needed from the community side to cross the finish line with this PR? Happy to test, review, anything... it is a bit of a shame that the de-facto standard CLI library doesn't have a time.Time flag like it has already for time.Duration

mmontes11 avatar Dec 18 '23 16:12 mmontes11

Good to see this has been approved... Can it be merged?

Kapparina avatar Aug 24 '24 07:08 Kapparina

Good to see this has been approved... Can it be merged?

@Kapparina i wish it was this easy :(

image

max-frank avatar Sep 05 '24 06:09 max-frank