Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor database input flavor error #64

Merged
merged 1 commit into from
Feb 6, 2024
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
6 changes: 2 additions & 4 deletions internal/cmd/mongodbflex/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,12 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) {

if flavorId == nil && (cpu == nil || ram == nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Service: "mongodbflex",
Operation: cmd.Use,
Cmd: cmd,
}
}
if flavorId != nil && (cpu != nil || ram != nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Service: "mongodbflex",
Operation: cmd.Use,
Cmd: cmd,
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/mongodbflex/instance/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {

if flavorId != nil && (cpu != nil || ram != nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Service: "mongodbflex",
Operation: cmd.Use,
Cmd: cmd,
Args: inputArgs,
}
}

Expand Down
6 changes: 2 additions & 4 deletions internal/cmd/postgresflex/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,12 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) {

if flavorId == nil && (cpu == nil || ram == nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Service: "postgresflex",
Operation: cmd.Use,
Cmd: cmd,
}
}
if flavorId != nil && (cpu != nil || ram != nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Service: "postgresflex",
Operation: cmd.Use,
Cmd: cmd,
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/postgresflex/instance/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {

if flavorId != nil && (cpu != nil || ram != nil) {
return nil, &cliErr.DatabaseInputFlavorError{
Service: "postgresflex",
Operation: cmd.Use,
Cmd: cmd,
Args: inputArgs,
}
}

Expand Down
18 changes: 14 additions & 4 deletions internal/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ For more details on the available plans, run:
DATABASE_INVALID_INPUT_FLAVOR = `the instance flavor was not correctly provided.

Either provide flavor ID by:
$ stackit %[1]s instance %[2]s --project-id xxx --flavor-id <FLAVOR ID> [flags]
$ %[1]s --flavor-id <FLAVOR ID> [flags]
joaopalet marked this conversation as resolved.
Show resolved Hide resolved

or provide CPU and RAM:
$ stackit %[1]s instance %[2]s --project-id xxx --cpu <CPU> --ram <RAM> [flags]
$ %[1]s --cpu <CPU> --ram <RAM> [flags]

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

DATABASE_INVALID_FLAVOR = `the provided instance flavor is not valid.

Expand Down Expand Up @@ -131,6 +131,7 @@ func (e *DSAInputPlanError) Error() string {
if len(e.Args) > 0 {
fullCommandPath = fmt.Sprintf("%s %s", fullCommandPath, strings.Join(e.Args, " "))
}
// Assumes a structure of the form "stackit <service> <resource> <operation>"
service := e.Cmd.Parent().Parent().Use

return fmt.Sprintf(DSA_INVALID_INPUT_PLAN, fullCommandPath, service)
Expand All @@ -148,10 +149,19 @@ func (e *DSAInvalidPlanError) Error() string {
type DatabaseInputFlavorError struct {
Service string
Operation string
Cmd *cobra.Command
Args []string
}

func (e *DatabaseInputFlavorError) Error() string {
return fmt.Sprintf(DATABASE_INVALID_INPUT_FLAVOR, e.Service, e.Operation)
fullCommandPath := e.Cmd.CommandPath()
if len(e.Args) > 0 {
fullCommandPath = fmt.Sprintf("%s %s", fullCommandPath, strings.Join(e.Args, " "))
}
// Assumes a structure of the form "stackit <service> <resource> <operation>"
service := e.Cmd.Parent().Parent().Use

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

type DatabaseInvalidFlavorError struct {
Expand Down
Loading