2023-01-26 18:55:38 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
2023-01-26 18:55:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type defineDefaultWorkspaceRoot struct{}
|
|
|
|
|
|
|
|
// DefineDefaultWorkspaceRoot defines the default workspace root path.
|
|
|
|
func DefineDefaultWorkspaceRoot() bundle.Mutator {
|
|
|
|
return &defineDefaultWorkspaceRoot{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defineDefaultWorkspaceRoot) Name() string {
|
|
|
|
return "DefineDefaultWorkspaceRoot"
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (m *defineDefaultWorkspaceRoot) Apply(ctx context.Context, b *bundle.Bundle) error {
|
2023-04-12 14:54:36 +00:00
|
|
|
if b.Config.Workspace.RootPath != "" {
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if b.Config.Bundle.Name == "" {
|
2023-05-24 12:45:19 +00:00
|
|
|
return fmt.Errorf("unable to define default workspace root: bundle name not defined")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if b.Config.Bundle.Environment == "" {
|
2023-05-24 12:45:19 +00:00
|
|
|
return fmt.Errorf("unable to define default workspace root: bundle environment not selected")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 14:54:36 +00:00
|
|
|
b.Config.Workspace.RootPath = fmt.Sprintf(
|
2023-01-26 18:55:38 +00:00
|
|
|
"~/.bundle/%s/%s",
|
|
|
|
b.Config.Bundle.Name,
|
|
|
|
b.Config.Bundle.Environment,
|
|
|
|
)
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|