You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Flag Action should be called when value is set by alternative sources. #2041
Are you running the latest v3 release? The list of releases is here. v3.0.0-beta1
Did you check the manual for your release? The v3 manual is here.
Did you perform a search about this feature? Here's the GitHub guide about searching.
What problem does this solve?
Fix action beeing called for all circumstances when a value is set by either a flag or alternative source. Currently the flag action is only executed when given as argument.
changed the title [-]Flag Action should be called when value is by alternative sources. [/-][+]Flag Action should be called when value is set by alternative sources. [/+]on Jan 6, 2025
The problem is that by default we arent running FlagAction for "non local" flags. Flags which are "non local" are available to all subcommands as well and there was a discussion as to how flag actions should be run for these kinds of flags. Local means that the flag is local only to current command and will have its flag actions run. Let me think how to proceed with this.
Activity
[-]Flag Action should be called when value is by alternative sources. [/-][+]Flag Action should be called when value is set by alternative sources. [/+]dearchap commentedon Jan 12, 2025
@project0 Can you set Local: true for cli.StringFlag and try ?
project0 commentedon Jan 12, 2025
@dearchap indeed, setting Local true populates the value. Is this the intended behavior? If so, documenting it would be beneficial in this case.
dearchap commentedon Jan 12, 2025
The problem is that by default we arent running FlagAction for "non local" flags. Flags which are "non local" are available to all subcommands as well and there was a discussion as to how flag actions should be run for these kinds of flags. Local means that the flag is local only to current command and will have its flag actions run. Let me think how to proceed with this.
cc @urfave/cli
dearchap commentedon Jan 12, 2025
In this case suppose your flag is "non local" you could invoke it something like this
we can run action for all flags(including log level ) for subcmd
but say you invoke it like this
the log-level flag is set from environment when should the flag action be run ? or for example
It starts getting complicated.
adamcohen2 commentedon Apr 17, 2025
I've run into this same situation. This seems to be an undocumented breaking change in behaviour between
v2andv3:github.com/urfave/cli/v2Click to expand code
Output:
go run . serve CUSTOM_VAR Action Servegithub.com/urfave/cli/v3Click to expand code
Output:
go run . serve ServeI've also tried adding
Local: trueto&cli.StringFlag, but this doesn't change the behaviour:Click to expand code
Output:
go run . serve ServeI have the following questions:
Local: true, why doesn't it work in the above example?Thanks!