Files
atlantis/server/core/runtime/env_step_runner.go
Sarvar Muminov 90e92e3a13 chore: move CommandContext and CommandResult to models (#193) (#2093)
* Moved CommandContext and CommandResult to models (#193)

* Moved CommandContext and CommandResult to models

* move from models to command

rename CommandContext -> Context
rename CommandResult -> Result

* moved command related helpers into command package

* move ProjectCommandContext and ProjectResult to command/project package

* move project command context and project result

* revert unrelated code

* move tests

* fix left over

* fix linting

* fix tests

* remove unused import

* fix project context dependencies

* fix depenedecies

* fix typo
2022-03-21 10:36:13 -07:00

28 lines
921 B
Go

package runtime
import (
"strings"
"github.com/runatlantis/atlantis/server/events/command"
)
// EnvStepRunner set environment variables.
type EnvStepRunner struct {
RunStepRunner *RunStepRunner
}
// Run runs the env step command.
// value is the value for the environment variable. If set this is returned as
// the value. Otherwise command is run and its output is the value returned.
func (r *EnvStepRunner) Run(ctx command.ProjectContext, command string, value string, path string, envs map[string]string) (string, error) {
if value != "" {
return value, nil
}
res, err := r.RunStepRunner.Run(ctx, command, path, envs)
// Trim newline from res to support running `echo env_value` which has
// a newline. We don't recommend users run echo -n env_value to remove the
// newline because -n doesn't work in the sh shell which is what we use
// to run commands.
return strings.TrimSuffix(res, "\n"), err
}