refactor(cmd/root): simplify `parseEnvs` (#2162)
Prior to this commit, `parseEnvs` accept two parameters: 1. env []string 2. envs map[string]string `parseEnvs` then do a `nil` check for `env`. However, we never pass a `nil` `env` to `parseEnvs` in `newRunCommand`. This commit simplify the `parseEnvs` function to accept just one `env []string` parameter and return the result as `map[string]string` instead. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
6a8c42ac53
commit
424fd5e02b
26
cmd/root.go
26
cmd/root.go
|
@ -297,19 +297,17 @@ func cleanup(inputs *Input) func(*cobra.Command, []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEnvs(env []string, envs map[string]string) bool {
|
func parseEnvs(env []string) map[string]string {
|
||||||
if env != nil {
|
envs := make(map[string]string, len(env))
|
||||||
for _, envVar := range env {
|
for _, envVar := range env {
|
||||||
e := strings.SplitN(envVar, `=`, 2)
|
e := strings.SplitN(envVar, `=`, 2)
|
||||||
if len(e) == 2 {
|
if len(e) == 2 {
|
||||||
envs[e[0]] = e[1]
|
envs[e[0]] = e[1]
|
||||||
} else {
|
} else {
|
||||||
envs[e[0]] = ""
|
envs[e[0]] = ""
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return envs
|
||||||
}
|
}
|
||||||
|
|
||||||
func readYamlFile(file string) (map[string]string, error) {
|
func readYamlFile(file string) (map[string]string, error) {
|
||||||
|
@ -415,13 +413,11 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Loading environment from %s", input.Envfile())
|
log.Debugf("Loading environment from %s", input.Envfile())
|
||||||
envs := make(map[string]string)
|
envs := parseEnvs(input.envs)
|
||||||
_ = parseEnvs(input.envs, envs)
|
|
||||||
_ = readEnvs(input.Envfile(), envs)
|
_ = readEnvs(input.Envfile(), envs)
|
||||||
|
|
||||||
log.Debugf("Loading action inputs from %s", input.Inputfile())
|
log.Debugf("Loading action inputs from %s", input.Inputfile())
|
||||||
inputs := make(map[string]string)
|
inputs := parseEnvs(input.inputs)
|
||||||
_ = parseEnvs(input.inputs, inputs)
|
|
||||||
_ = readEnvs(input.Inputfile(), inputs)
|
_ = readEnvs(input.Inputfile(), inputs)
|
||||||
|
|
||||||
log.Debugf("Loading secrets from %s", input.Secretfile())
|
log.Debugf("Loading secrets from %s", input.Secretfile())
|
||||||
|
|
Loading…
Reference in New Issue