summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEng Zer Jun <engzerjun@gmail.com>2024-01-24 04:06:31 +0100
committerGitHub <noreply@github.com>2024-01-24 04:06:31 +0100
commit424fd5e02b4be9fce8aae518420b0499c08cb31b (patch)
tree276c448761ba173191ddb457abff48de23ba6c06
parentAdd containerd's normalized architectures to archMapper (#2168) (diff)
downloadforgejo-act-424fd5e02b4be9fce8aae518420b0499c08cb31b.tar.xz
forgejo-act-424fd5e02b4be9fce8aae518420b0499c08cb31b.zip
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>
-rw-r--r--cmd/root.go26
1 files changed, 11 insertions, 15 deletions
diff --git a/cmd/root.go b/cmd/root.go
index 319fdd5..e506699 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -297,19 +297,17 @@ func cleanup(inputs *Input) func(*cobra.Command, []string) {
}
}
-func parseEnvs(env []string, envs map[string]string) bool {
- if env != nil {
- for _, envVar := range env {
- e := strings.SplitN(envVar, `=`, 2)
- if len(e) == 2 {
- envs[e[0]] = e[1]
- } else {
- envs[e[0]] = ""
- }
+func parseEnvs(env []string) map[string]string {
+ envs := make(map[string]string, len(env))
+ for _, envVar := range env {
+ e := strings.SplitN(envVar, `=`, 2)
+ if len(e) == 2 {
+ envs[e[0]] = e[1]
+ } else {
+ envs[e[0]] = ""
}
- return true
}
- return false
+ return envs
}
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())
- envs := make(map[string]string)
- _ = parseEnvs(input.envs, envs)
+ envs := parseEnvs(input.envs)
_ = readEnvs(input.Envfile(), envs)
log.Debugf("Loading action inputs from %s", input.Inputfile())
- inputs := make(map[string]string)
- _ = parseEnvs(input.inputs, inputs)
+ inputs := parseEnvs(input.inputs)
_ = readEnvs(input.Inputfile(), inputs)
log.Debugf("Loading secrets from %s", input.Secretfile())