Skip to content

Commit

Permalink
feat: add prompting to confirm application commands
Browse files Browse the repository at this point in the history
Signed-off-by: pashakostohrys <[email protected]>
  • Loading branch information
pasha-codefresh committed Nov 4, 2024
1 parent 8cf990b commit 15a18df
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/yaml"

"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/headless"
"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/utils"
cmdutil "github.com/argoproj/argo-cd/v2/cmd/util"
"github.com/argoproj/argo-cd/v2/controller"
argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
Expand Down Expand Up @@ -912,13 +913,20 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
}

cmdutil.SetAppSpecOptions(c.Flags(), &app.Spec, &appOpts, sourcePosition)
_, err = appIf.UpdateSpec(ctx, &application.ApplicationUpdateSpecRequest{
Name: &app.Name,
Spec: &app.Spec,
Validate: &appOpts.Validate,
AppNamespace: &appNs,
})
errors.CheckError(err)

promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled)
canUnset := promptUtil.Confirm("Are you sure you want to unset the parameters? [y/n]")
if canUnset {
_, err = appIf.UpdateSpec(ctx, &application.ApplicationUpdateSpecRequest{
Name: &app.Name,
Spec: &app.Spec,
Validate: &appOpts.Validate,
AppNamespace: &appNs,
})
errors.CheckError(err)
} else {
fmt.Println("The command to unset the parameters has been cancelled.")
}
},
}
command.Flags().StringVarP(&appNamespace, "app-namespace", "N", "", "Unset application parameters in namespace")
Expand Down Expand Up @@ -3190,14 +3198,20 @@ func NewApplicationRemoveSourceCommand(clientOpts *argocdclient.ClientOptions) *

app.Spec.Sources = append(app.Spec.Sources[:sourcePosition-1], app.Spec.Sources[sourcePosition:]...)

_, err = appIf.UpdateSpec(ctx, &application.ApplicationUpdateSpecRequest{
Name: &app.Name,
Spec: &app.Spec,
AppNamespace: &appNs,
})
errors.CheckError(err)
promptUtil := utils.NewPrompt(clientOpts.PromptsEnabled)
canDelete := promptUtil.Confirm("Are you sure you want to delete the source? [y/n]")
if canDelete {
_, err = appIf.UpdateSpec(ctx, &application.ApplicationUpdateSpecRequest{
Name: &app.Name,
Spec: &app.Spec,
AppNamespace: &appNs,
})
errors.CheckError(err)

fmt.Printf("Application '%s' updated successfully\n", app.ObjectMeta.Name)
fmt.Printf("Application '%s' updated successfully\n", app.ObjectMeta.Name)
} else {
fmt.Println("The command to delete the source was cancelled")
}
},
}
command.Flags().StringVarP(&appNamespace, "app-namespace", "N", "", "Namespace of the target application where the source will be appended")
Expand Down

0 comments on commit 15a18df

Please sign in to comment.