mirror of https://github.com/databricks/cli.git
more cleanup
This commit is contained in:
parent
0c9fbf7b23
commit
edf705188d
|
@ -31,9 +31,9 @@ The current working directory of the provided command will be set to the root
|
||||||
of the bundle.
|
of the bundle.
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
1. databricks bundle exec -- echo hello
|
1. databricks bundle exec -- echo "hello, world"
|
||||||
2. databricks bundle exec -- /bin/bash -c "echo hello""
|
2. databricks bundle exec -- /bin/bash -c "echo hello"
|
||||||
3. databricks bundle exec -- uv run pytest"`,
|
3. databricks bundle exec -- uv run pytest`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if cmd.ArgsLenAtDash() != 0 {
|
if cmd.ArgsLenAtDash() != 0 {
|
||||||
return fmt.Errorf("Please add a '--' separator. Usage: 'databricks bundle exec -- %s'", strings.Join(args, " "))
|
return fmt.Errorf("Please add a '--' separator. Usage: 'databricks bundle exec -- %s'", strings.Join(args, " "))
|
||||||
|
@ -50,19 +50,20 @@ Example usage:
|
||||||
|
|
||||||
env := auth.ProcessEnv(root.ConfigUsed(cmd.Context()))
|
env := auth.ProcessEnv(root.ConfigUsed(cmd.Context()))
|
||||||
|
|
||||||
// If user has specified a target, pass it to the child command. If the
|
// If user has specified a target, pass it to the child command. DABs
|
||||||
// target is the default target, we don't need to pass it explicitly since
|
// defines a "default" target which is a placeholder if no target is defined.
|
||||||
// the CLI will use the default target by default.
|
// If that's the case, i.e. no targets are defined, then do not pass the target.
|
||||||
|
//
|
||||||
// This is only useful for when the Databricks CLI is the child command.
|
// This is only useful for when the Databricks CLI is the child command.
|
||||||
if b.Config.Bundle.Target != mutator.DefaultTargetPlaceholder {
|
if b.Config.Bundle.Target != mutator.DefaultTargetPlaceholder {
|
||||||
env = append(env, "DATABRICKS_BUNDLE_TARGET="+b.Config.Bundle.Target)
|
env = append(env, "DATABRICKS_BUNDLE_TARGET="+b.Config.Bundle.Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the bundle has a profile, explicitly pass it to the child command.
|
// If the bundle has a profile configured, explicitly pass it to the child command.
|
||||||
// This is unnecessary for tools that follow the unified authentication spec.
|
//
|
||||||
// However, because the CLI can read the profile from the bundle itself, we
|
// This is only useful for when the Databricks CLI is the child command,
|
||||||
// need to pass it explicitly.
|
// since if we do not explicitly pass the profile, the CLI will use the
|
||||||
// This is only useful for when the Databricks CLI is the child command.
|
// profile configured in the bundle YAML configuration (if any).We don't propagate the exit code as is because exit codes
|
||||||
if b.Config.Workspace.Profile != "" {
|
if b.Config.Workspace.Profile != "" {
|
||||||
env = append(env, "DATABRICKS_CONFIG_PROFILE="+b.Config.Workspace.Profile)
|
env = append(env, "DATABRICKS_CONFIG_PROFILE="+b.Config.Workspace.Profile)
|
||||||
}
|
}
|
||||||
|
@ -92,10 +93,12 @@ Example usage:
|
||||||
// Wait for the command to finish.
|
// Wait for the command to finish.
|
||||||
err := childCmd.Wait()
|
err := childCmd.Wait()
|
||||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||||
// We don't propagate the exit code as is because exit codes for
|
// We don't make the parent CLI process exit with the same exit code
|
||||||
// the CLI have not been standardized yet. At some point in the
|
// as the child process because the exit codes for the CLI have not
|
||||||
// future we might want to associate specific exit codes with
|
// been standardized yet.
|
||||||
// specific classes of errors.
|
//
|
||||||
|
// This keeps the door open for us to associate specific exit codes
|
||||||
|
// with specific classes of errors in the future.
|
||||||
return &exitCodeErr{
|
return &exitCodeErr{
|
||||||
exitCode: exitErr.ExitCode(),
|
exitCode: exitErr.ExitCode(),
|
||||||
args: args,
|
args: args,
|
||||||
|
|
|
@ -13,27 +13,6 @@ import (
|
||||||
// The original environment is restored upon test completion.
|
// The original environment is restored upon test completion.
|
||||||
// Note: use of this function is incompatible with parallel execution.
|
// Note: use of this function is incompatible with parallel execution.
|
||||||
func CleanupEnvironment(t TestingT) {
|
func CleanupEnvironment(t TestingT) {
|
||||||
path := os.Getenv("PATH")
|
|
||||||
pwd := os.Getenv("PWD")
|
|
||||||
|
|
||||||
// Clear all environment variables.
|
|
||||||
ClearEnvironment(t)
|
|
||||||
|
|
||||||
// We use t.Setenv instead of os.Setenv because the former actively
|
|
||||||
// prevents a test being run with t.Parallel. Modifying the environment
|
|
||||||
// within a test is not compatible with running tests in parallel
|
|
||||||
// because of isolation; the environment is scoped to the process.
|
|
||||||
t.Setenv("PATH", path)
|
|
||||||
t.Setenv("HOME", pwd)
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
t.Setenv("USERPROFILE", pwd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearEnvironment sets up an empty environment with no environment variables set.
|
|
||||||
// The original environment is restored upon test completion.
|
|
||||||
// Note: use of this function is incompatible with parallel execution
|
|
||||||
func ClearEnvironment(t TestingT) {
|
|
||||||
// Restore environment when test finishes.
|
// Restore environment when test finishes.
|
||||||
environ := os.Environ()
|
environ := os.Environ()
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
|
@ -44,7 +23,19 @@ func ClearEnvironment(t TestingT) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
path := os.Getenv("PATH")
|
||||||
|
pwd := os.Getenv("PWD")
|
||||||
os.Clearenv()
|
os.Clearenv()
|
||||||
|
|
||||||
|
// We use t.Setenv instead of os.Setenv because the former actively
|
||||||
|
// prevents a test being run with t.Parallel. Modifying the environment
|
||||||
|
// within a test is not compatible with running tests in parallel
|
||||||
|
// because of isolation; the environment is scoped to the process.
|
||||||
|
t.Setenv("PATH", path)
|
||||||
|
t.Setenv("HOME", pwd)
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Setenv("USERPROFILE", pwd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes into specified directory for the duration of the test.
|
// Changes into specified directory for the duration of the test.
|
||||||
|
|
Loading…
Reference in New Issue