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

time.Time flags #742

Open
lesovsky opened this issue Sep 8, 2018 · 6 comments
Open

time.Time flags #742

lesovsky opened this issue Sep 8, 2018 · 6 comments
Labels
area/flags-args Changes to functionality around command line flags and args kind/feature A feature request for cobra; new or enhanced behavior

Comments

@lesovsky
Copy link

lesovsky commented Sep 8, 2018

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?

@github-actions
Copy link

github-actions bot commented Apr 9, 2020

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

@vikramarsid
Copy link

@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!

@johnSchnake
Copy link
Collaborator

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 johnSchnake added area/flags-args Changes to functionality around command line flags and args kind/feature A feature request for cobra; new or enhanced behavior and removed kind/stale labels Mar 5, 2022
hoshsadiq pushed a commit to zulucmd/zflag that referenced this issue Dec 31, 2022
This PR implements support for `time.Time` flags which can be used to accept timestamps as input directly (see spf13/cobra#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.

Merge spf13#348
@donacarr
Copy link

Hi there...
any update on this feature?

@max-frank
Copy link

max-frank commented Jun 15, 2023

@donacarr spf13/pflag#348 has been ready to be merged for a while now, but still waiting for review.

CC: @johnSchnake

@mmontes11
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flags-args Changes to functionality around command line flags and args kind/feature A feature request for cobra; new or enhanced behavior
Projects
None yet
Development

No branches or pull requests

6 participants