diff --git a/v2/ahoy.go b/v2/ahoy.go index a400790..ba65dcb 100644 --- a/v2/ahoy.go +++ b/v2/ahoy.go @@ -33,7 +33,7 @@ type Command struct { Description string Usage string Cmd string - Env string + Env []string Hide bool Optional bool Imports []string @@ -276,9 +276,12 @@ func getCommands(config Config) []cli.Command { // If defined, included specified command-level environment variables. // Note that this will intentionally override any conflicting variables // defined in the 'global' env file. - if cmd.Env != "" { - cmdEnvFile := filepath.Join(AhoyConf.srcDir, cmd.Env) - envVars = append(envVars, getEnvironmentVars(cmdEnvFile)...) + if cmd.Env != nil { + for _, file := range cmd.Env { + cmdEnvFile := filepath.Join(AhoyConf.srcDir, file) + envVars = append(envVars, getEnvironmentVars(cmdEnvFile)...) + + } } if verbose { diff --git a/v2/testdata/.env.local1 b/v2/testdata/.env.local1 new file mode 100644 index 0000000..8b11c36 --- /dev/null +++ b/v2/testdata/.env.local1 @@ -0,0 +1,2 @@ +UNIQUE=unique +TO_BE_OVERRIDDEN=local1 diff --git a/v2/testdata/.env.local2 b/v2/testdata/.env.local2 new file mode 100644 index 0000000..dacb29e --- /dev/null +++ b/v2/testdata/.env.local2 @@ -0,0 +1 @@ +TO_BE_OVERRIDDEN=local2 diff --git a/v2/testdata/env-multiple.ahoy.yml b/v2/testdata/env-multiple.ahoy.yml index 682679b..80b0017 100644 --- a/v2/testdata/env-multiple.ahoy.yml +++ b/v2/testdata/env-multiple.ahoy.yml @@ -9,3 +9,13 @@ commands: cmd: echo $COMMAND test-overridden: cmd: echo $TO_BE_OVERRIDDEN + test-cmd-multiple-1: + cmd: echo $UNIQUE + env: + - .env.local1 + - .env.local2 + test-cmd-multiple-2: + cmd: echo $TO_BE_OVERRIDDEN + env: + - .env.local1 + - .env.local2 diff --git a/v2/testdata/env.ahoy.yml b/v2/testdata/env.ahoy.yml index bba0188..dd5cad5 100644 --- a/v2/testdata/env.ahoy.yml +++ b/v2/testdata/env.ahoy.yml @@ -7,12 +7,15 @@ commands: test-cmd: cmd: echo $COMMAND - env: .env.cmd + env: + - .env.cmd test-override: cmd: echo $TO_BE_OVERRIDDEN - env: .env.cmd + env: + - .env.cmd test-invalid-env: cmd: echo "This should not print!" - env: .env.thisfiledoesntexist + env: + - .env.thisfiledoesntexist diff --git a/v2/tests/environment-variables.bats b/v2/tests/environment-variables.bats index c16babd..2ffbc9e 100644 --- a/v2/tests/environment-variables.bats +++ b/v2/tests/environment-variables.bats @@ -2,7 +2,6 @@ @test "Command-level variables can be defined and used" { run ./ahoy -f testdata/env.ahoy.yml test-cmd - echo "$output" [[ "$output" == "123456789" ]] } @@ -31,3 +30,14 @@ run ./ahoy -f testdata/env-multiple.ahoy.yml test-overridden [[ "$output" = "after" ]] } + +@test "Multiple command env files can be defined" { + run ./ahoy -f testdata/env-multiple.ahoy.yml test-cmd-multiple-1 + echo $output + [[ "$output" = "unique" ]] + + run ./ahoy -f testdata/env-multiple.ahoy.yml test-cmd-multiple-2 + echo $output + [[ "$output" = "local2" ]] +} +