Skip to content

Commit

Permalink
Fix setting env name with a property (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
antlai-temporal authored May 22, 2024
1 parent 9581b4e commit 69dd427
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions temporalcli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func NewCommandContext(ctx context.Context, options CommandOptions) (*CommandCon
return cctx, stop, nil
}

const temporalEnv = "TEMPORAL_ENV"

func (c *CommandContext) preprocessOptions() error {
if len(c.Options.Args) == 0 {
c.Options.Args = os.Args[1:]
Expand Down Expand Up @@ -123,6 +125,9 @@ func (c *CommandContext) preprocessOptions() error {

if c.Options.EnvConfigName == "" {
c.Options.EnvConfigName = "default"
if envVal, ok := c.Options.LookupEnv(temporalEnv); ok {
c.Options.EnvConfigName = envVal
}
// Default to --env, prefetched from CLI args
for i, arg := range c.Options.Args {
if arg == "--env" && i+1 < len(c.Options.Args) {
Expand Down
19 changes: 19 additions & 0 deletions temporalcli/commands.workflow_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,25 @@ func (s *SharedServerSuite) TestWorkflow_Execute_EnvConfig() {
)
s.NoError(res.Err)
s.ContainsOnSameLine(res.Stdout.String(), "Result", `"env-conf-input"`)

// And we can specify `env` with a property
s.CommandHarness.Options.LookupEnv = func(key string) (string, bool) {
if key == "TEMPORAL_ENV" {
return "myenv", true
}
return "", false
}
res = s.Execute(
"workflow", "execute",
"--env-file", tmpFile.Name(),
"--address", s.Address(),
"--task-queue", s.Worker().Options.TaskQueue,
"--type", "DevWorkflow",
"--workflow-id", "my-id3",
)
s.NoError(res.Err)
s.ContainsOnSameLine(res.Stdout.String(), "Result", `"env-conf-input"`)

}

func (s *SharedServerSuite) TestWorkflow_Execute_CodecEndpoint() {
Expand Down

0 comments on commit 69dd427

Please sign in to comment.