|
| 1 | +package bundle |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + "github.com/databricks/cli/bundle" |
| 8 | + "github.com/databricks/cli/bundle/config/validate" |
| 9 | + "github.com/databricks/cli/bundle/phases" |
| 10 | + "github.com/databricks/cli/cmd/bundle/utils" |
| 11 | + "github.com/databricks/cli/cmd/root" |
| 12 | + "github.com/databricks/cli/libs/cmdio" |
| 13 | + "github.com/databricks/cli/libs/logdiag" |
| 14 | + "github.com/spf13/cobra" |
| 15 | +) |
| 16 | + |
| 17 | +func newPlanCommand() *cobra.Command { |
| 18 | + cmd := &cobra.Command{ |
| 19 | + Use: "plan", |
| 20 | + Short: "Show deployment plan", |
| 21 | + Args: root.NoArgs, |
| 22 | + |
| 23 | + // Output format may change without notice; main use case is in acceptance tests. |
| 24 | + // Today, this command also uploads libraries, which is not the intent here. We need to refactor |
| 25 | + // libraries.Upload() mutator to separate config mutation with actual upload. |
| 26 | + Hidden: true, |
| 27 | + } |
| 28 | + |
| 29 | + var force bool |
| 30 | + var clusterId string |
| 31 | + cmd.Flags().BoolVar(&force, "force", false, "Force-override Git branch validation.") |
| 32 | + cmd.Flags().StringVar(&clusterId, "compute-id", "", "Override cluster in the deployment with the given compute ID.") |
| 33 | + cmd.Flags().StringVarP(&clusterId, "cluster-id", "c", "", "Override cluster in the deployment with the given cluster ID.") |
| 34 | + cmd.Flags().MarkDeprecated("compute-id", "use --cluster-id instead") |
| 35 | + |
| 36 | + cmd.RunE = func(cmd *cobra.Command, args []string) error { |
| 37 | + ctx := logdiag.InitContext(cmd.Context()) |
| 38 | + cmd.SetContext(ctx) |
| 39 | + |
| 40 | + b := utils.ConfigureBundleWithVariables(cmd) |
| 41 | + if b == nil || logdiag.HasError(ctx) { |
| 42 | + return root.ErrAlreadyPrinted |
| 43 | + } |
| 44 | + |
| 45 | + bundle.ApplyFuncContext(ctx, b, func(context.Context, *bundle.Bundle) { |
| 46 | + b.Config.Bundle.Force = force |
| 47 | + |
| 48 | + if cmd.Flag("compute-id").Changed { |
| 49 | + b.Config.Bundle.ClusterId = clusterId |
| 50 | + } |
| 51 | + |
| 52 | + if cmd.Flag("cluster-id").Changed { |
| 53 | + b.Config.Bundle.ClusterId = clusterId |
| 54 | + } |
| 55 | + }) |
| 56 | + |
| 57 | + phases.Initialize(ctx, b) |
| 58 | + |
| 59 | + if logdiag.HasError(ctx) { |
| 60 | + return root.ErrAlreadyPrinted |
| 61 | + } |
| 62 | + |
| 63 | + bundle.ApplyContext(ctx, b, validate.FastValidate()) |
| 64 | + |
| 65 | + if logdiag.HasError(ctx) { |
| 66 | + return root.ErrAlreadyPrinted |
| 67 | + } |
| 68 | + |
| 69 | + phases.Build(ctx, b) |
| 70 | + |
| 71 | + if logdiag.HasError(ctx) { |
| 72 | + return root.ErrAlreadyPrinted |
| 73 | + } |
| 74 | + |
| 75 | + changes := phases.Diff(ctx, b) |
| 76 | + |
| 77 | + for _, change := range changes { |
| 78 | + cmdio.LogString(ctx, fmt.Sprintf("%s %s.%s", change.ActionType, change.Group, change.Name)) |
| 79 | + } |
| 80 | + |
| 81 | + if logdiag.HasError(ctx) { |
| 82 | + return root.ErrAlreadyPrinted |
| 83 | + } |
| 84 | + |
| 85 | + return nil |
| 86 | + } |
| 87 | + |
| 88 | + return cmd |
| 89 | +} |
0 commit comments