prefix for environment variables
cmorent opened this issue · 6 comments
cmorent commented
It would be great to have a function like "SetEnvPrefix" or something to be able to add a prefix to the environment variables. As an example:
var age int
flag.IntVar(&age, "age", 27, "my age")
flag.SetEnvPrefix("svc")
And then be able to do the following:
$ SVC_AGE=25 go run gopher.go
What do you think ?
funnylookinhat commented
Yes, this would be fantastic! Generally options on the command line don't need any context, but environment variables can easily overlap common terms like host
, address
, etc.
fancyapp --address=127.0.0.1
vs. FANCY_ADDRESS=127.0.0.1 fancyapp
funnylookinhat commented
I think this will do it: #24
BastienM commented
Any ETA on the merge ?
smyrman commented
I'm just another user, but it's already possible to do either:
flag.CommandLine = flag.NewFlagSetWithEnvPrefix("my-set", "MY_PREFIX", flag.ExitOnError)
...
flag.Parse()
Or to use your own FlagSet directly:
set := flag.NewFlagSetWithEnvPrefix("my-set", "MY_PREFIX", flag.ExitOnError)
...
set.Parse(os.Args[1:])
funnylookinhat commented
@smyrman Hey you're right - wow that function was hidden in extras and I never saw it. 😄