2023-01-26 18:55:38 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"path"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
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"
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundle) error {
|
2023-04-12 14:54:36 +00:00
|
|
|
root := b.Config.Workspace.RootPath
|
2023-01-26 18:55:38 +00:00
|
|
|
if root == "" {
|
2023-05-24 12:45:19 +00:00
|
|
|
return fmt.Errorf("unable to define default workspace paths: workspace root not defined")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 14:54:36 +00:00
|
|
|
if b.Config.Workspace.FilesPath == "" {
|
|
|
|
b.Config.Workspace.FilesPath = path.Join(root, "files")
|
2023-01-26 18:55:38 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 14:54:36 +00:00
|
|
|
if b.Config.Workspace.ArtifactsPath == "" {
|
|
|
|
b.Config.Workspace.ArtifactsPath = 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
|
|
|
}
|