diff --git a/integration-tests/variable_write_test.go b/integration-tests/variable_write_test.go index b3f5be3b..2a4be8c0 100644 --- a/integration-tests/variable_write_test.go +++ b/integration-tests/variable_write_test.go @@ -98,6 +98,23 @@ func TestVariableCreate(t *testing.T) { assertTrimmed(t, "false", f.Run("var:get", "-p", p, "env:TEST", "-l", "p", "-P", "visible_runtime")) } +func TestVariableCreateDefaultEnvironment(t *testing.T) { + // Regression test for CLI-164: using "-e ." (the default-environment code) + // must not fail form validation of the --environment option. + s := setupVariableTest(t) + s.apiHandler.SetEnvironments([]*mockapi.Environment{s.mainEnv}) + + f, p := s.factory, s.projectID + + _, stdErr, err := f.RunCombinedOutput("var:create", "-p", p, "-e", ".", "-l", "e", "env:FOOBAR", "--value", "bar foo") + assert.NoError(t, err) + assert.Contains(t, stdErr, "Selecting default environment") + assert.Contains(t, stdErr, "Creating variable env:FOOBAR on the environment main") + assert.NotContains(t, stdErr, "is not one of") + + assertTrimmed(t, "bar foo", f.Run("var:get", "-p", p, "-e", "main", "env:FOOBAR", "-P", "value")) +} + func TestVariableCreateWithAppScope(t *testing.T) { s := setupVariableTest(t) diff --git a/legacy/src/Command/Variable/VariableCreateCommand.php b/legacy/src/Command/Variable/VariableCreateCommand.php index 2e2ce2b5..aa425cdb 100644 --- a/legacy/src/Command/Variable/VariableCreateCommand.php +++ b/legacy/src/Command/Variable/VariableCreateCommand.php @@ -64,6 +64,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int $selection = $this->selector->getSelection($input, new SelectorConfig(envRequired: false)); $this->selection = $selection; + // The 'environment' form field validates the --environment option + // against the list of environment IDs. Replace the default-environment + // placeholder ('.') with the resolved environment ID so validation + // succeeds. See CLI-164. + if ($selection->hasEnvironment() && $input->getOption('environment') === Selector::DEFAULT_ENVIRONMENT_CODE) { + $input->setOption('environment', $selection->getEnvironment()->id); + } + // Merge the 'name' argument with the --name option. if ($input->getArgument('name')) { if ($input->getOption('name')) {