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
Flag ignores default value #99
Flag ignores default value #99
Conversation
Not really sure why this is failing. Seems Travis CI can't find goveralls but it was definitely installed earlier in the build
Earlier in the build:
|
@Alec-Bakholdin thank you for contribution! I think these build failures have to do with Go command line usage changes, let me have a look. Edit: Right, trying this on my desktop with same 1.18.3 installed:
|
Looks like the service is having issues. I created a PR to fix the original problem, but it appears the service is currently down and responding with 405 errors. I will check in on it later once they fixed issues on their side (and meantime I think it is worth changing to Github actions perhaps and see if they have coverage reporting within Github service). https://status.coveralls.io/ |
argument.go
Outdated
@@ -501,6 +502,9 @@ func (o *arg) setDefaultFiles() error { | |||
func (o *arg) setDefault() error { | |||
// Only set default if it was not parsed, and default value was defined | |||
if !o.parsed && o.opts != nil && o.opts.Default != nil { | |||
if o.noDefault { | |||
return fmt.Errorf("argument [%s, %s] does not support default values", o.sname, o.lname) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this solution would fix the problem, I think it may cause issues with any existing code, which should be avoided (i am trying to maintain this library backward compatible as much as possible). If some code was setting it to false
which would make it work as expected, with this change that code will start failing.
I think better options that maintain some sort of compatibility is to either ignore Options.Default
for Flag or to add logic for inverting Flag value (Options.Default
defaults to false
, if set to true
then if flag present the value set to false, otherwise true).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. What do you think about adding an argType field to the arg interface that makes it easier to introduce type-specific functionality like this? Currently, determining argument type is difficult down the line in functions like setDefault(). I think an enum would work really well, and would not change any existing behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding an argType field to the arg interface that makes it easier to introduce type-specific functionality like this?
Yes, I were considering something like that for V2, but current schedule does not allow me to start working on it just yet. My concern with the current one is just the backward compatibility, this lib is used by a number of tools, and would not want to introduce a breaking change here. So any solution you like that would not break existing code outright should be okay I think.
@Alec-Bakholdin Please rebase the change onto master to fix coverage reporting |
@Alec-Bakholdin I am sorry to be pedantic about this, can you please avoid cross merging master branch and use rebase instead? |
…nality of defaults for flags
… flag-ignores-default-value
…nality of defaults for flags
Not at all! I'm sorry, I'm not familiar with this process, as this is my first contribution ever. I tried to rebase once more, but I think I may have screwed things up again... I thought I was doing it right. Is the process not to just type |
Merged to master in #103 |
Resolves #98
Adds one new field to the arg interface "noDefault" that Flag uses