Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions internal/cmd/opensearch/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ func configureFlags(cmd *cobra.Command) {
}

func parseInput(cmd *cobra.Command) (*inputModel, error) {
service := "opensearch"
operation := cmd.Use

globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, &cliErr.ProjectIdError{}
Expand All @@ -169,14 +166,12 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) {

if planId == nil && (planName == "" || version == "") {
return nil, &cliErr.DSAInputPlanError{
Service: service,
Operation: operation,
Cmd: cmd,
}
}
if planId != nil && (planName != "" || version != "") {
return nil, &cliErr.DSAInputPlanError{
Service: service,
Operation: operation,
Cmd: cmd,
}
}

Expand Down
6 changes: 2 additions & 4 deletions internal/cmd/opensearch/instance/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ func configureFlags(cmd *cobra.Command) {
}

func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
service := "opensearch"
operation := cmd.Use
instanceId := inputArgs[0]

globalFlags := globalflags.Parse(cmd)
Expand All @@ -172,8 +170,8 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {

if planId != nil && (planName != "" || version != "") {
return nil, &cliErr.DSAInputPlanError{
Service: service,
Operation: operation,
Cmd: cmd,
Args: inputArgs,
}
}

Expand Down
25 changes: 16 additions & 9 deletions internal/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package errors

import (
"fmt"
"strings"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -37,14 +38,14 @@ For more details run:

DSA_INVALID_INPUT_PLAN = `the instance plan was not correctly provided.
Comment thread
joaopalet marked this conversation as resolved.

Either provide plan-id by running:
$ stackit %[1]s instance %[2]s --project-id xxx --name my-instance --plan-id <PLAN ID>
Either provide the plan ID:
$ %[1]s --plan-id <PLAN ID> [flags]

or provide plan-name and version:
$ stackit %[1]s instance %[2]s --project-id xxx --name my-instance --plan-name <PLAN NAME> --version <VERSION>
or provide plan name and version:
$ %[1]s --plan-name <PLAN NAME> --version <VERSION> [flags]

For more details on the available plans, run:
$ stackit %[1]s plans`
$ stackit %[2]s plans`

DSA_INVALID_PLAN = `the provided instance plan is not valid.

Expand All @@ -55,7 +56,7 @@ For more details on the available plans, run:

DATABASE_INVALID_INPUT_FLAVOR = `the instance flavor was not correctly provided.

Either provide flavor-id by running:
Either provide flavor ID by:
$ stackit %[1]s instance %[2]s --project-id xxx --flavor-id <FLAVOR ID> [flags]

or provide CPU and RAM:
Expand Down Expand Up @@ -121,12 +122,18 @@ func (e *ActivateServiceAccountError) Error() string {
}

type DSAInputPlanError struct {
Service string
Operation string
Cmd *cobra.Command
Args []string
}

func (e *DSAInputPlanError) Error() string {
return fmt.Sprintf(DSA_INVALID_INPUT_PLAN, e.Service, e.Operation)
fullCommandPath := e.Cmd.CommandPath()
if len(e.Args) > 0 {
fullCommandPath = fmt.Sprintf("%s %s", fullCommandPath, strings.Join(e.Args, " "))
}
service := e.Cmd.Parent().Parent().Use

return fmt.Sprintf(DSA_INVALID_INPUT_PLAN, fullCommandPath, service)
}

type DSAInvalidPlanError struct {
Expand Down