etcd: export SetFlagsFromEnv

This commit is contained in:
Brian Waldon 2014-09-24 16:12:06 -07:00
parent 18c300f80c
commit f7c353a703
2 changed files with 4 additions and 4 deletions

View File

@ -95,7 +95,7 @@ func main() {
flag.Usage = pkg.UsageWithIgnoredFlagsFunc(flag.CommandLine, deprecated) flag.Usage = pkg.UsageWithIgnoredFlagsFunc(flag.CommandLine, deprecated)
flag.Parse() flag.Parse()
setFlagsFromEnv(flag.CommandLine) SetFlagsFromEnv(flag.CommandLine)
if string(*proxyFlag) == proxyFlagValueOff { if string(*proxyFlag) == proxyFlagValueOff {
startEtcd() startEtcd()
@ -329,12 +329,12 @@ func (pf *ProxyFlag) String() string {
return string(*pf) return string(*pf)
} }
// setFlagsFromEnv parses all registered flags in the given flagset, // SetFlagsFromEnv parses all registered flags in the given flagset,
// and if they are not already set it attempts to set their values from // and if they are not already set it attempts to set their values from
// environment variables. Environment variables take the name of the flag but // environment variables. Environment variables take the name of the flag but
// are UPPERCASE, have the prefix "ETCD_", and any dashes are replaced by // are UPPERCASE, have the prefix "ETCD_", and any dashes are replaced by
// underscores - for example: some-flag => ETCD_SOME_FLAG // underscores - for example: some-flag => ETCD_SOME_FLAG
func setFlagsFromEnv(fs *flag.FlagSet) { func SetFlagsFromEnv(fs *flag.FlagSet) {
alreadySet := make(map[string]bool) alreadySet := make(map[string]bool)
fs.Visit(func(f *flag.Flag) { fs.Visit(func(f *flag.Flag) {
alreadySet[f.Name] = true alreadySet[f.Name] = true

View File

@ -30,7 +30,7 @@ func TestSetFlagsFromEnv(t *testing.T) {
} }
// now read the env and verify flags were updated as expected // now read the env and verify flags were updated as expected
setFlagsFromEnv(flag.CommandLine) SetFlagsFromEnv(flag.CommandLine)
for f, want := range map[string]string{ for f, want := range map[string]string{
"data-dir": "/foo/bar", "data-dir": "/foo/bar",
"peer-bind-addr": "1.2.3.4", "peer-bind-addr": "1.2.3.4",