feat(cli): Added an auto approve flag for apply
All checks were successful
ci / goreleaser (push) Successful in 1m53s

This commit is contained in:
Richard Robert Reitz 2025-10-02 14:52:40 +02:00
parent 975b5ad525
commit 51ce4ed111

View file

@ -18,6 +18,7 @@ import (
var ( var (
configFile string configFile string
dryRun bool dryRun bool
autoApprove bool
) )
var applyCmd = &cobra.Command{ var applyCmd = &cobra.Command{
@ -33,14 +34,14 @@ the necessary changes to deploy your applications across multiple cloudlets.`,
os.Exit(1) os.Exit(1)
} }
if err := runApply(configFile, dryRun); err != nil { if err := runApply(configFile, dryRun, autoApprove); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err) fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
}, },
} }
func runApply(configPath string, isDryRun bool) error { func runApply(configPath string, isDryRun bool, autoApprove bool) error {
// Step 1: Validate and resolve config file path // Step 1: Validate and resolve config file path
absPath, err := filepath.Abs(configPath) absPath, err := filepath.Abs(configPath)
if err != nil { if err != nil {
@ -112,7 +113,7 @@ func runApply(configPath string, isDryRun bool) error {
fmt.Printf("\nThis will perform %d actions. Estimated time: %v\n", fmt.Printf("\nThis will perform %d actions. Estimated time: %v\n",
result.Plan.TotalActions, result.Plan.EstimatedDuration) result.Plan.TotalActions, result.Plan.EstimatedDuration)
if !confirmDeployment() { if !autoApprove && !confirmDeployment() {
fmt.Println("Deployment cancelled.") fmt.Println("Deployment cancelled.")
return nil return nil
} }
@ -170,6 +171,7 @@ func init() {
applyCmd.Flags().StringVarP(&configFile, "file", "f", "", "configuration file path (required)") applyCmd.Flags().StringVarP(&configFile, "file", "f", "", "configuration file path (required)")
applyCmd.Flags().BoolVar(&dryRun, "dry-run", false, "preview changes without applying them") applyCmd.Flags().BoolVar(&dryRun, "dry-run", false, "preview changes without applying them")
applyCmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "automatically approve the deployment plan")
applyCmd.MarkFlagRequired("file") applyCmd.MarkFlagRequired("file")
} }