Refactor environment mapping into separate function
This commit is contained in:
parent
e3385e0a31
commit
4596f8c89b
2 changed files with 13 additions and 10 deletions
12
cmd/root.go
12
cmd/root.go
|
@ -101,3 +101,15 @@ func initLogger() {
|
||||||
|
|
||||||
log.SetLevel(lvl)
|
log.SetLevel(lvl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapEnvVars(envs map[string]string, cmd *cobra.Command) {
|
||||||
|
for env, flag := range envs {
|
||||||
|
flag := cmd.Flags().Lookup(flag)
|
||||||
|
flag.Usage = fmt.Sprintf("%v [env %v]", flag.Usage, env)
|
||||||
|
if value := os.Getenv(env); value != "" {
|
||||||
|
if err := flag.Value.Set(value); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -134,13 +133,5 @@ func init() {
|
||||||
"PHP_FPM_FIX_PROCESS_COUNT": "phpfpm.fix-process-count",
|
"PHP_FPM_FIX_PROCESS_COUNT": "phpfpm.fix-process-count",
|
||||||
}
|
}
|
||||||
|
|
||||||
for env, flag := range envs {
|
mapEnvVars(envs, serverCmd)
|
||||||
flag := serverCmd.Flags().Lookup(flag)
|
|
||||||
flag.Usage = fmt.Sprintf("%v [env %v]", flag.Usage, env)
|
|
||||||
if value := os.Getenv(env); value != "" {
|
|
||||||
if err := flag.Value.Set(value); err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue