mirror of https://github.com/databricks/cli.git
read target from flag
This commit is contained in:
parent
8c094db503
commit
5586121239
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/databricks/cli/bundle/config/mutator"
|
||||
"github.com/databricks/cli/cmd/root"
|
||||
"github.com/databricks/cli/libs/auth"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -42,13 +41,11 @@ Example usage:
|
|||
|
||||
env := auth.ProcessEnv(root.ConfigUsed(cmd.Context()))
|
||||
|
||||
// If user has specified a target, pass it to the child command. DABs
|
||||
// defines a "default" target which is a placeholder for when no target is defined.
|
||||
// If that's the case, i.e. no targets are defined, then do not pass the target.
|
||||
// If user has specified a target, pass it to the child command.
|
||||
//
|
||||
// This is only useful for when the Databricks CLI is the child command.
|
||||
if b.Config.Bundle.Target != mutator.DefaultTargetPlaceholder {
|
||||
env = append(env, "DATABRICKS_BUNDLE_TARGET="+b.Config.Bundle.Target)
|
||||
if target := root.GetTarget(cmd); target != "" {
|
||||
env = append(env, "DATABRICKS_CONFIG_TARGET="+target)
|
||||
}
|
||||
|
||||
// If the bundle has a profile configured, explicitly pass it to the child command.
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
// getTarget returns the name of the target to operate in.
|
||||
func getTarget(cmd *cobra.Command) (value string) {
|
||||
// GetTarget returns the name of the target to operate in.
|
||||
func GetTarget(cmd *cobra.Command) (value string) {
|
||||
target, isFlagSet := targetFlagValue(cmd)
|
||||
if isFlagSet {
|
||||
return target
|
||||
|
@ -77,7 +77,7 @@ func configureBundle(cmd *cobra.Command, b *bundle.Bundle) (*bundle.Bundle, diag
|
|||
// Load bundle and select target.
|
||||
ctx := cmd.Context()
|
||||
var diags diag.Diagnostics
|
||||
if target := getTarget(cmd); target == "" {
|
||||
if target := GetTarget(cmd); target == "" {
|
||||
diags = phases.LoadDefaultTarget(ctx, b)
|
||||
} else {
|
||||
diags = phases.LoadNamedTarget(ctx, b, target)
|
||||
|
|
|
@ -215,7 +215,7 @@ func TestTargetFlagFull(t *testing.T) {
|
|||
err := cmd.ExecuteContext(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "development", getTarget(cmd))
|
||||
assert.Equal(t, "development", GetTarget(cmd))
|
||||
}
|
||||
|
||||
func TestTargetFlagShort(t *testing.T) {
|
||||
|
@ -227,7 +227,7 @@ func TestTargetFlagShort(t *testing.T) {
|
|||
err := cmd.ExecuteContext(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "production", getTarget(cmd))
|
||||
assert.Equal(t, "production", GetTarget(cmd))
|
||||
}
|
||||
|
||||
// TODO: remove when environment flag is fully deprecated
|
||||
|
@ -241,5 +241,5 @@ func TestTargetEnvironmentFlag(t *testing.T) {
|
|||
err := cmd.ExecuteContext(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "development", getTarget(cmd))
|
||||
assert.Equal(t, "development", GetTarget(cmd))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue