Fixed --environment flag (#705)

## Changes
Fixed --environment flag

Fixes https://github.com/databricks/setup-cli/issues/35

## Tests
Added regression test
This commit is contained in:
Andrew Nester 2023-08-28 19:05:55 +02:00 committed by GitHub
parent 5f6289e3a7
commit 5477afe4f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -26,7 +26,7 @@ func getTarget(cmd *cobra.Command) (value string) {
oldFlag := cmd.Flag("environment")
if oldFlag != nil {
value = flag.Value.String()
value = oldFlag.Value.String()
if value != "" {
return
}

View File

@ -138,7 +138,7 @@ func TestTargetFlagFull(t *testing.T) {
err := cmd.ExecuteContext(ctx)
assert.NoError(t, err)
assert.Equal(t, cmd.Flag("target").Value.String(), "development")
assert.Equal(t, getTarget(cmd), "development")
}
func TestTargetFlagShort(t *testing.T) {
@ -150,5 +150,19 @@ func TestTargetFlagShort(t *testing.T) {
err := cmd.ExecuteContext(ctx)
assert.NoError(t, err)
assert.Equal(t, cmd.Flag("target").Value.String(), "production")
assert.Equal(t, getTarget(cmd), "production")
}
// TODO: remove when environment flag is fully deprecated
func TestTargetEnvironmentFlag(t *testing.T) {
cmd := emptyCommand(t)
initTargetFlag(cmd)
initEnvironmentFlag(cmd)
cmd.SetArgs([]string{"version", "--environment", "development"})
ctx := context.Background()
err := cmd.ExecuteContext(ctx)
assert.NoError(t, err)
assert.Equal(t, getTarget(cmd), "development")
}