diff --git a/internal/cmd/mongodbflex/instance/create/create.go b/internal/cmd/mongodbflex/instance/create/create.go index 1c96c251..daced79c 100644 --- a/internal/cmd/mongodbflex/instance/create/create.go +++ b/internal/cmd/mongodbflex/instance/create/create.go @@ -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, } } diff --git a/internal/cmd/mongodbflex/instance/update/update.go b/internal/cmd/mongodbflex/instance/update/update.go index afeb0bb6..c458fa9e 100644 --- a/internal/cmd/mongodbflex/instance/update/update.go +++ b/internal/cmd/mongodbflex/instance/update/update.go @@ -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, } } diff --git a/internal/cmd/postgresflex/instance/create/create.go b/internal/cmd/postgresflex/instance/create/create.go index 5650e949..46064dd0 100644 --- a/internal/cmd/postgresflex/instance/create/create.go +++ b/internal/cmd/postgresflex/instance/create/create.go @@ -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, } } diff --git a/internal/cmd/postgresflex/instance/update/update.go b/internal/cmd/postgresflex/instance/update/update.go index 8273fc4b..71e16644 100644 --- a/internal/cmd/postgresflex/instance/update/update.go +++ b/internal/cmd/postgresflex/instance/update/update.go @@ -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, } } diff --git a/internal/pkg/errors/errors.go b/internal/pkg/errors/errors.go index 153e5c99..a9753f5e 100644 --- a/internal/pkg/errors/errors.go +++ b/internal/pkg/errors/errors.go @@ -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 [flags] + $ %[1]s --flavor-id [flags] or provide CPU and RAM: - $ stackit %[1]s instance %[2]s --project-id xxx --cpu --ram [flags] + $ %[1]s --cpu --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. @@ -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 := e.Cmd.Parent().Parent().Use return fmt.Sprintf(DSA_INVALID_INPUT_PLAN, fullCommandPath, service) @@ -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 := e.Cmd.Parent().Parent().Use + + return fmt.Sprintf(DATABASE_INVALID_INPUT_FLAVOR, fullCommandPath, service) } type DatabaseInvalidFlavorError struct {