2023-01-26 18:55:38 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"path"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2023-01-26 18:55:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type defineDefaultWorkspacePaths struct{}
|
|
|
|
|
|
|
|
// DefineDefaultWorkspacePaths sets workspace paths if they aren't already set.
|
|
|
|
func DefineDefaultWorkspacePaths() bundle.Mutator {
|
|
|
|
return &defineDefaultWorkspacePaths{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defineDefaultWorkspacePaths) Name() string {
|
|
|
|
return "DefaultWorkspacePaths"
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2023-04-12 14:54:36 +00:00
|
|
|
root := b.Config.Workspace.RootPath
|
2023-01-26 18:55:38 +00:00
|
|
|
if root == "" {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.Errorf("unable to define default workspace paths: workspace root not defined")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
2023-11-15 13:37:26 +00:00
|
|
|
if b.Config.Workspace.FilePath == "" {
|
|
|
|
b.Config.Workspace.FilePath = path.Join(root, "files")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
2024-10-02 13:55:40 +00:00
|
|
|
if b.Config.Workspace.ResourcePath == "" {
|
|
|
|
b.Config.Workspace.ResourcePath = path.Join(root, "resources")
|
|
|
|
}
|
|
|
|
|
2023-11-15 13:37:26 +00:00
|
|
|
if b.Config.Workspace.ArtifactPath == "" {
|
|
|
|
b.Config.Workspace.ArtifactPath = path.Join(root, "artifacts")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 14:54:36 +00:00
|
|
|
if b.Config.Workspace.StatePath == "" {
|
|
|
|
b.Config.Workspace.StatePath = path.Join(root, "state")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|