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)
|
||||
}
|
||||
|
||||
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 (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -134,13 +133,5 @@ func init() {
|
|||
"PHP_FPM_FIX_PROCESS_COUNT": "phpfpm.fix-process-count",
|
||||
}
|
||||
|
||||
for env, flag := range envs {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
mapEnvVars(envs, serverCmd)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue