github.com/databricks/cli@v0.203.0/bundle/config/mutator/default_workspace_paths.go (about)

     1  package mutator
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"path"
     7  
     8  	"github.com/databricks/cli/bundle"
     9  )
    10  
    11  type defineDefaultWorkspacePaths struct{}
    12  
    13  // DefineDefaultWorkspacePaths sets workspace paths if they aren't already set.
    14  func DefineDefaultWorkspacePaths() bundle.Mutator {
    15  	return &defineDefaultWorkspacePaths{}
    16  }
    17  
    18  func (m *defineDefaultWorkspacePaths) Name() string {
    19  	return "DefaultWorkspacePaths"
    20  }
    21  
    22  func (m *defineDefaultWorkspacePaths) Apply(ctx context.Context, b *bundle.Bundle) error {
    23  	root := b.Config.Workspace.RootPath
    24  	if root == "" {
    25  		return fmt.Errorf("unable to define default workspace paths: workspace root not defined")
    26  	}
    27  
    28  	if b.Config.Workspace.FilesPath == "" {
    29  		b.Config.Workspace.FilesPath = path.Join(root, "files")
    30  	}
    31  
    32  	if b.Config.Workspace.ArtifactsPath == "" {
    33  		b.Config.Workspace.ArtifactsPath = path.Join(root, "artifacts")
    34  	}
    35  
    36  	if b.Config.Workspace.StatePath == "" {
    37  		b.Config.Workspace.StatePath = path.Join(root, "state")
    38  	}
    39  
    40  	return nil
    41  }