Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env-loader: Allow for providing environments directory via arg #288

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading