cobra icon indicating copy to clipboard operation
cobra copied to clipboard

time.Time flags

Open lesovsky opened this issue 7 years ago • 6 comments

Hi,

Is there simple way to handle time flags? For example, I use the following flags in my cli:

./a.out --start="2018-09-08 12:00:00" --end="2018-09-09 12:00:00"

I have not found according functions in go doc, and use the following workaround: I save start/end values using StringVarP and then define layout and parse strings with time.Parse.

Does cobra provide functions for handling time flags?

lesovsky avatar Sep 08 '18 07:09 lesovsky

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Apr 09 '20 00:04 github-actions[bot]

@spf13 @bogem Any updates on this issue? I will be glad to open a PR for this feature, let me know what do you think. Thank you!

vikramarsid avatar Jan 15 '21 23:01 vikramarsid

Seems like there was positive feedback on this issue and it would be relatively straight forward to support a new flag type.

This would go into https://github.com/spf13/pflag though. I'd be happy to review a PR for that if you tag me. I think that you just need to provide the ability to define the flag and the format string you expect.

johnSchnake avatar Mar 05 '22 18:03 johnSchnake

Hi there... any update on this feature?

donacarr avatar Mar 16 '23 11:03 donacarr

@donacarr https://github.com/spf13/pflag/pull/348 has been ready to be merged for a while now, but still waiting for review.

CC: @johnSchnake

max-frank avatar Jun 15 '23 23:06 max-frank

I think this would be an awesome addition to this fantastic library, any chance we can get a review here?:

  • https://github.com/spf13/pflag/pull/348

mmontes11 avatar Dec 18 '23 16:12 mmontes11