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
14
cmd/root.go
14
cmd/root.go
|
@ -297,8 +297,8 @@ 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 {
|
||||||
|
@ -307,9 +307,7 @@ func parseEnvs(env []string, envs map[string]string) bool {
|
||||||
envs[e[0]] = ""
|
envs[e[0]] = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return envs
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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