-
Notifications
You must be signed in to change notification settings - Fork 403
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
Use default value for non-bool flag when there's no value supplied #16
Comments
First, http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ls.c#n542 seems to indicate that
...works as intended. |
No it's not the intended behaviour. With |
To be more specific, I want to be able to mark a flag as |
Yeah, you're right. I went over this earlier today (not at 1 AM like last night 😄) and realized what you meant. I think there are some hacky workarounds, but they're just that -- hacky. |
If I understand correctly, you'd like to be able to specify the value of a flag provided without an argument, in the same way that a bool flag without an argument is assumed to be Can I ask, do you need to know after parsing whether an argument was provided or not? Or is it enough just to have some implicit default the way we do with bool flags. For example, it looks like with getopt one can check whether there is an argument supplied at all: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/ls.c#n1869 |
I'm trying to do everything If there's any workaround without radical change to |
spf13/pflag (a fork of ogier) has this support. See https://github.com/spf13/pflag#setting-no-option-default-values-for-flags |
Merge ogier/pflag and enable travis
Currently only
flag.Bool
can be used as--flag
without supplying a value. There's some situation when non-bool flag should be able to use default value when no value was supplied.E.g. the
ls
command incoreutils
have a--color
string flag. When there's no value supplied, it assume to bealways
. Right now there's no way to do the same usingpflag
The text was updated successfully, but these errors were encountered: