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

PreAction does not trigger on a flag when it is specified by an env variable. #175

Open
james-lawrence opened this issue Feb 1, 2017 · 2 comments

Comments

@james-lawrence
Copy link

var enabled bool
cmd.Flag("profiler-enable", "enable the profiler").Default("false").
		Envar("PROFILER_ENABLED").PreAction(execute).BoolVar(&enabled)

func execute(c *kingpin.ParseContext) error {
  log.Println("enabling profiler")
  return nil
}
spike --profiler-enable
# enabling profiler
PROFILER_ENABLED=true spike
# nothing output
@alecthomas
Copy link
Owner

Good catch. I'll try to fix this tonight.

@alecthomas
Copy link
Owner

Hmm, ok. So this occurs because envars change the default value prior to parsing. I think it would actually require a fair amount of effort to fix, so I might just change the documented behaviour to: Envar(name): Allow the default value to be set via environment variable.. That is not exactly ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants