-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Run flag actions when Value is set #1973
Comments
@samlaf That is the intended behaviour. You cannot trigger a flag action on default. Also the |
@dearchap hmm that's weird, because it's public on my import and I've been using it with this behavior (tested that it's working): Could you explain or link me to a place where the intended behaviour is explained? My use case seems like a valid behaviour to me. |
@samlaf you are actually using v2. The v3 tag on this issue confused me. Here is the code which decides whether to call a flag action or not. https://github.com/urfave/cli/blob/v2-maint/app.go#L473 . Also note that v2 is in maint mode so any changes in this behavior need to be done on v3. |
@dearchap oh yes my bad… opened it initially woth the v3 template but then realized I was using v2 so erased the template msg but left the tag. Is v3 production ready right now? And if I switch to it how would I reproduce the current behavior I’m using of running the action on the default value (nice to have default be something human readable as it’s shown as an example to users in the —help output) |
v3 is in beta state and is mostly usable. |
@samlaf Would you like to make a PR for this ? |
Don’t have time these days so can’t promise anything. Unless you point me to the exact/approximate where the change would be. Not familiar with Urfave internal codebase, let alone v3. |
You can look at command.Run which calls runFlagActions |
@samlaf It doesnt really make sense to run a Flag Action all the time. It defeats the purpose. It would just be a block of code that you could put in the Command.Action . I'm going to close this issue . |
@dearchap its about locality of code. If I have 3 such flags then command.Action becomes crowded no? Makes more sense for me to have the parsing right next to the flag. |
I agree but this is a very atypical use case. |
Believe that Actions are only run when a flag is set. This means that when I have an Action which I want to run even on the default Value, I have to set HasBeenSet to true, like below
Is this intended behavior? Should we not also run an action when a Value is set?
The text was updated successfully, but these errors were encountered: