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

golangflag: use goflag.DefValue #203

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

holycheater
Copy link

The piece of code in question breaks priority behavior for spf13/viper, because the flag/env precedence order in viper is actually flag, env, default flag.

func main() {
	var s string
	flag.StringVar(&s, "param", "def value", "")
	flag.Parse()
	pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
	viper.BindPFlags(pflag.CommandLine)
	viper.AutomaticEnv()
	log.Println(viper.GetString("param"))
}
PARAM=foo go run ./main.go -param bar // expecting flag param to have higher priority than env param
9/03/14 20:02:06 foo

@CLAassistant
Copy link

CLAassistant commented Mar 14, 2019

CLA assistant check
All committers have signed the CLA.

@therealmitchconnors
Copy link
Collaborator

Can you add a regression test for this behavior?

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

Successfully merging this pull request may close these issues.

3 participants