Add auto-approve support for bundle deploy

This commit is contained in:
Shreyas Goenka 2023-07-05 16:59:13 +02:00
parent cd89e5b1ac
commit 385043db4e
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 19 additions and 7 deletions

View File

@ -1,8 +1,11 @@
package bundle package bundle
import ( import (
"fmt"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/phases" "github.com/databricks/cli/bundle/phases"
"github.com/databricks/cli/libs/cmdio"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -17,6 +20,15 @@ var deployCmd = &cobra.Command{
// If `--force` is specified, force acquisition of the deployment lock. // If `--force` is specified, force acquisition of the deployment lock.
b.Config.Bundle.Lock.Force = forceDeploy b.Config.Bundle.Lock.Force = forceDeploy
// If `--auto-approve`` is specified, we skip confirmation checks
b.AutoApprove = autoApproveDeploy
// we require auto-approve for non tty terminals since interactive consent
// is not possible
if !cmdio.IsErrTTY(cmd.Context()) && !autoApproveDeploy {
return fmt.Errorf("please specify --auto-approve to skip interactive confirmation checks for non tty consoles")
}
return bundle.Apply(cmd.Context(), b, bundle.Seq( return bundle.Apply(cmd.Context(), b, bundle.Seq(
phases.Initialize(), phases.Initialize(),
phases.Build(), phases.Build(),
@ -26,8 +38,10 @@ var deployCmd = &cobra.Command{
} }
var forceDeploy bool var forceDeploy bool
var autoApproveDeploy bool
func init() { func init() {
AddCommand(deployCmd) AddCommand(deployCmd)
deployCmd.Flags().BoolVar(&autoApproveDeploy, "auto-approve", false, "Skip interactive approvals for deployment")
deployCmd.Flags().BoolVar(&forceDeploy, "force", false, "Force acquisition of deployment lock.") deployCmd.Flags().BoolVar(&forceDeploy, "force", false, "Force acquisition of deployment lock.")
} }

View File

@ -2,14 +2,12 @@ package bundle
import ( import (
"fmt" "fmt"
"os"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/phases" "github.com/databricks/cli/bundle/phases"
"github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/flags"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/term"
) )
var destroyCmd = &cobra.Command{ var destroyCmd = &cobra.Command{
@ -25,11 +23,11 @@ var destroyCmd = &cobra.Command{
b.Config.Bundle.Lock.Force = forceDestroy b.Config.Bundle.Lock.Force = forceDestroy
// If `--auto-approve`` is specified, we skip confirmation checks // If `--auto-approve`` is specified, we skip confirmation checks
b.AutoApprove = autoApprove b.AutoApprove = autoApproveDestroy
// we require auto-approve for non tty terminals since interactive consent // we require auto-approve for non tty terminals since interactive consent
// is not possible // is not possible
if !term.IsTerminal(int(os.Stderr.Fd())) && !autoApprove { if !cmdio.IsErrTTY(cmd.Context()) && !autoApproveDestroy {
return fmt.Errorf("please specify --auto-approve to skip interactive confirmation checks for non tty consoles") return fmt.Errorf("please specify --auto-approve to skip interactive confirmation checks for non tty consoles")
} }
@ -38,7 +36,7 @@ var destroyCmd = &cobra.Command{
if !ok { if !ok {
return fmt.Errorf("progress logger not found") return fmt.Errorf("progress logger not found")
} }
if logger.Mode == flags.ModeJson && !autoApprove { if logger.Mode == flags.ModeJson && !autoApproveDestroy {
return fmt.Errorf("please specify --auto-approve since selected logging format is json") return fmt.Errorf("please specify --auto-approve since selected logging format is json")
} }
@ -50,11 +48,11 @@ var destroyCmd = &cobra.Command{
}, },
} }
var autoApprove bool var autoApproveDestroy bool
var forceDestroy bool var forceDestroy bool
func init() { func init() {
AddCommand(destroyCmd) AddCommand(destroyCmd)
destroyCmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals for deleting resources and files") destroyCmd.Flags().BoolVar(&autoApproveDestroy, "auto-approve", false, "Skip interactive approvals for deleting resources and files")
destroyCmd.Flags().BoolVar(&forceDestroy, "force", false, "Force acquisition of deployment lock.") destroyCmd.Flags().BoolVar(&forceDestroy, "force", false, "Force acquisition of deployment lock.")
} }