Skip to content

Commit

Permalink
Merge pull request #27 from stackitcloud/hs/confirmation-prompt-v2
Browse files Browse the repository at this point in the history
Implement confirmation prompts
  • Loading branch information
hcsa73 authored Nov 24, 2023
2 parents 0be5cb5 + 448e562 commit 5fa7923
Show file tree
Hide file tree
Showing 34 changed files with 393 additions and 37 deletions.
11 changes: 10 additions & 1 deletion internal/cmd/dns/record-set/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
Expand Down Expand Up @@ -46,6 +47,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := "Are you sure you want to create a record-set?"
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -89,7 +98,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/dns/record-set/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
Expand Down Expand Up @@ -38,6 +39,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to delete record-set %s? (This cannot be undone)", model.RecordSetId)
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -77,7 +86,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/dns/record-set/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/dns/record-set/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/dns/record-set/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
Expand Down Expand Up @@ -46,6 +47,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to update record-set %s?", model.RecordSetId)
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -86,7 +95,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
13 changes: 12 additions & 1 deletion internal/cmd/dns/zone/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
Expand Down Expand Up @@ -59,6 +60,16 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := "Are you sure you want to create a zone?"
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

cmd.OutOrStdout()

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -107,7 +118,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/dns/zone/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
Expand Down Expand Up @@ -36,6 +37,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to delete zone %s? (This cannot be undone)", model.ZoneId)
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -74,7 +83,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/dns/zone/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/dns/zone/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/dns/zone/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client"
Expand Down Expand Up @@ -56,6 +57,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to update zone %s?", model.ZoneId)
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -104,7 +113,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/postgresql/credential/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresql/client"
Expand Down Expand Up @@ -37,6 +38,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := "Are you sure you want to create a credential?"
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -72,7 +81,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/postgresql/credential/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresql/client"
Expand Down Expand Up @@ -37,6 +38,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to delete credential %s? (This cannot be undone)", model.CredentialId)
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -69,7 +78,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/postgresql/credential/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/postgresql/credential/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/postgresql/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresql/client"
Expand Down Expand Up @@ -61,6 +62,14 @@ func NewCmd() *cobra.Command {
return err
}

if !model.AssumeYes {
prompt := "Are you sure you want to create an instance?"
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -115,7 +124,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
12 changes: 11 additions & 1 deletion internal/cmd/postgresql/instance/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresql/client"
Expand Down Expand Up @@ -35,6 +36,15 @@ func NewCmd() *cobra.Command {
if err != nil {
return err
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to delete instance %s? (This cannot be undone)", model.InstanceId)
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
Expand Down Expand Up @@ -70,7 +80,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/postgresql/instance/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/postgresql/instance/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func configureFlags(cmd *cobra.Command) {
}

func parseFlags(cmd *cobra.Command) (*flagModel, error) {
globalFlags := globalflags.Parse()
globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, fmt.Errorf("project ID not set")
}
Expand Down
Loading

0 comments on commit 5fa7923

Please sign in to comment.