Skip to content

Commit

Permalink
Merge pull request #288 from gravitational/fred/env-loader-provide-dir-1
Browse files Browse the repository at this point in the history
env-loader: Allow for providing environments directory via arg
  • Loading branch information
fheinecke authored Nov 6, 2024
2 parents a6abc83 + 9f8b8e9 commit f48d22e
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tools/env-loader/cmd/env-loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ import (
const EnvVarPrefix = "ENV_LOADER_"

type config struct {
Environment string
ValueSets []string
Values []string
Writer string
EnvironmentsDirectory string
Environment string
ValueSets []string
Values []string
Writer string
}

func parseCLI() *config {
c := &config{}

kingpin.Flag("environments-directory", "Path to the directory containing all environments, defaulting to the repo root").
Short('d').
Envar(EnvVarPrefix + "ENVIRONMENT").
StringVar(&c.EnvironmentsDirectory)

kingpin.Flag("environment", "Name of the environment containing the values to load").
Envar(EnvVarPrefix + "ENVIRONMENT").
Short('e').
Expand Down Expand Up @@ -69,7 +75,14 @@ func parseCLI() *config {

func run(c *config) error {
// Load in values
envValues, err := envloader.LoadEnvironmentValues(c.Environment, c.ValueSets)
var envValues map[string]string
var err error
if c.EnvironmentsDirectory != "" {
envValues, err = envloader.LoadEnvironmentValuesInDirectory(c.EnvironmentsDirectory, c.Environment, c.ValueSets)
} else {
envValues, err = envloader.LoadEnvironmentValues(c.Environment, c.ValueSets)
}

if err != nil {
return trace.Wrap(err, "failed to load all environment values")
}
Expand Down

0 comments on commit f48d22e

Please sign in to comment.