Skip to content

Commit a704842

Browse files
committed
Implement a global assume yes option
1 parent 49d7015 commit a704842

File tree

7 files changed

+44
-32
lines changed

7 files changed

+44
-32
lines changed

internal/pkg/cli/command/apiKey/delete.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import (
1414
)
1515

1616
type DeleteApiKeyOptions struct {
17-
apiKeyId string
18-
skipConfirmation bool
17+
apiKeyId string
1918
}
2019

2120
func NewDeleteKeyCmd() *cobra.Command {
@@ -27,7 +26,8 @@ func NewDeleteKeyCmd() *cobra.Command {
2726
GroupID: help.GROUP_API_KEYS.ID,
2827
Example: heredoc.Doc(`
2928
$ pc target -o "my-org" -p "my-project"
30-
$ pc api-key delete -i "api-key-id"
29+
$ pc api-key delete -i "api-key-id"
30+
$ pc api-key delete -i "api-key-id" -y
3131
`),
3232
Run: func(cmd *cobra.Command, args []string) {
3333
ac := sdk.NewPineconeAdminClient()
@@ -41,7 +41,9 @@ func NewDeleteKeyCmd() *cobra.Command {
4141
exit.Error(err)
4242
}
4343

44-
if !options.skipConfirmation {
44+
// Check if -y flag is set
45+
assumeYes, _ := cmd.Flags().GetBool("assume-yes")
46+
if !assumeYes {
4547
confirmDeleteApiKey(keyToDelete.Name)
4648
}
4749

@@ -57,7 +59,6 @@ func NewDeleteKeyCmd() *cobra.Command {
5759
cmd.Flags().StringVarP(&options.apiKeyId, "id", "i", "", "The ID of the API key to delete")
5860
_ = cmd.MarkFlagRequired("id")
5961

60-
cmd.Flags().BoolVar(&options.skipConfirmation, "skip-confirmation", false, "Skip deletion confirmation prompt")
6162
return cmd
6263
}
6364

internal/pkg/cli/command/index/create.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ func runCreateIndexCmd(options createIndexOptions, cmd *cobra.Command, args []st
141141

142142
indexpresenters.PrintIndexCreateConfigTable(&inferredOptions)
143143

144-
// Ask for user confirmation
145-
question := "Is this configuration correct? Do you want to proceed with creating the index?"
146-
if !interactive.GetConfirmation(question) {
147-
pcio.Println(style.InfoMsg("Index creation cancelled."))
148-
return
144+
// Ask for user confirmation unless -y flag is set
145+
assumeYes, _ := cmd.Flags().GetBool("assume-yes")
146+
if !assumeYes {
147+
question := "Is this configuration correct? Do you want to proceed with creating the index?"
148+
if !interactive.GetConfirmation(question) {
149+
pcio.Println(style.InfoMsg("Index creation cancelled."))
150+
return
151+
}
149152
}
150153

151154
// index tags

internal/pkg/cli/command/index/delete.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ func NewDeleteCmd() *cobra.Command {
2929
Run: func(cmd *cobra.Command, args []string) {
3030
options.name = args[0]
3131

32-
// Ask for user confirmation
33-
msg.WarnMsgMultiLine(
34-
pcio.Sprintf("This will delete the index %s and all its data.", style.ResourceName(options.name)),
35-
"This action cannot be undone.",
36-
)
37-
question := "Are you sure you want to proceed with the deletion?"
38-
if !interactive.GetConfirmation(question) {
39-
pcio.Println(style.InfoMsg("Index deletion cancelled."))
40-
return
32+
// Ask for user confirmation unless -y flag is set
33+
assumeYes, _ := cmd.Flags().GetBool("assume-yes")
34+
if !assumeYes {
35+
// Ask for user confirmation
36+
msg.WarnMsgMultiLine(
37+
pcio.Sprintf("This will delete the index %s and all its data.", style.ResourceName(options.name)),
38+
"This action cannot be undone.",
39+
)
40+
question := "Are you sure you want to proceed with the deletion?"
41+
if !interactive.GetConfirmation(question) {
42+
pcio.Println(style.InfoMsg("Index deletion cancelled."))
43+
return
44+
}
4145
}
4246

4347
ctx := context.Background()

internal/pkg/cli/command/organization/delete.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import (
1414
)
1515

1616
type DeleteOrganizationCmdOptions struct {
17-
organizationID string
18-
skipConfirmation bool
19-
json bool
17+
organizationID string
18+
json bool
2019
}
2120

2221
func NewDeleteOrganizationCmd() *cobra.Command {
@@ -27,7 +26,7 @@ func NewDeleteOrganizationCmd() *cobra.Command {
2726
Short: "Delete an organization by ID",
2827
Example: heredoc.Doc(`
2928
$ pc organization delete -i <organization-id>
30-
$ pc organization delete -i <organization-id> --skip-confirmation
29+
$ pc organization delete -i <organization-id> -y
3130
`),
3231
GroupID: help.GROUP_ORGANIZATIONS.ID,
3332
Run: func(cmd *cobra.Command, args []string) {
@@ -40,7 +39,9 @@ func NewDeleteOrganizationCmd() *cobra.Command {
4039
exit.Error(err)
4140
}
4241

43-
if !options.skipConfirmation {
42+
// Check if -y flag is set
43+
assumeYes, _ := cmd.Flags().GetBool("assume-yes")
44+
if !assumeYes {
4445
confirmDelete(org.Name, org.Id)
4546
}
4647

@@ -66,7 +67,6 @@ func NewDeleteOrganizationCmd() *cobra.Command {
6667
_ = cmd.MarkFlagRequired("id")
6768

6869
// optional flags
69-
cmd.Flags().BoolVar(&options.skipConfirmation, "skip-confirmation", false, "Skip the deletion confirmation prompt")
7070
cmd.Flags().BoolVar(&options.json, "json", false, "Output as JSON")
7171

7272
return cmd

internal/pkg/cli/command/project/delete.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import (
1616
)
1717

1818
type DeleteProjectCmdOptions struct {
19-
projectId string
20-
skipConfirmation bool
21-
json bool
19+
projectId string
20+
json bool
2221
}
2322

2423
func NewDeleteProjectCmd() *cobra.Command {
@@ -55,7 +54,9 @@ func NewDeleteProjectCmd() *cobra.Command {
5554
verifyNoIndexes(projToDelete.Id, projToDelete.Name)
5655
verifyNoCollections(projToDelete.Id, projToDelete.Name)
5756

58-
if !options.skipConfirmation {
57+
// Check if -y flag is set
58+
assumeYes, _ := cmd.Flags().GetBool("assume-yes")
59+
if !assumeYes {
5960
confirmDelete(projToDelete.Name)
6061
}
6162

@@ -78,7 +79,6 @@ func NewDeleteProjectCmd() *cobra.Command {
7879

7980
// optional flags
8081
cmd.Flags().StringVarP(&options.projectId, "id", "i", "", "ID of the project to delete")
81-
cmd.Flags().BoolVar(&options.skipConfirmation, "skip-confirmation", false, "Skip the deletion confirmation prompt")
8282
cmd.Flags().BoolVar(&options.json, "json", false, "Output as JSON")
8383

8484
return cmd

internal/pkg/cli/command/root/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
var rootCmd *cobra.Command
2525

2626
type GlobalOptions struct {
27-
quiet bool
28-
verbose bool
27+
quiet bool
28+
verbose bool
29+
assumeYes bool
2930
}
3031

3132
func Execute() {
@@ -93,4 +94,5 @@ Get started by logging in with
9394
// Global flags
9495
rootCmd.PersistentFlags().BoolVarP(&globalOptions.quiet, "quiet", "q", false, "suppress output")
9596
rootCmd.PersistentFlags().BoolVarP(&globalOptions.verbose, "verbose", "V", false, "show detailed error information")
97+
rootCmd.PersistentFlags().BoolVarP(&globalOptions.assumeYes, "assume-yes", "y", false, "assume yes to all confirmation requests")
9698
}

internal/pkg/utils/interactive/confirmation.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (m ConfirmationModel) View() string {
7676
// GetConfirmation prompts the user to confirm an action
7777
// Returns true if the user confirmed with 'y', false if they declined with 'n'
7878
func GetConfirmation(question string) bool {
79+
7980
m := NewConfirmationModel(question)
8081

8182
p := tea.NewProgram(m)
@@ -99,6 +100,7 @@ func GetConfirmation(question string) bool {
99100
// This allows callers to distinguish between "no" and "quit" responses (though both 'n' and 'q' now map to ConfirmationNo)
100101
// Note: Ctrl+C will kill the entire CLI process and is not handled gracefully
101102
func GetConfirmationResult(question string) ConfirmationResult {
103+
102104
m := NewConfirmationModel(question)
103105

104106
p := tea.NewProgram(m)

0 commit comments

Comments
 (0)