diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index b2c78ee15..2477679de 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -2,6 +2,7 @@ package cmd import ( "encoding/json" + "errors" "fmt" "os" "path" @@ -164,11 +165,19 @@ func preCustomCommand( parentCommand *cobra.Command, commandConfig *schema.Command, ) { - var err error - + var sb strings.Builder if len(args) != len(commandConfig.Arguments) { - err = fmt.Errorf("invalid number of arguments, %d argument(s) required", len(commandConfig.Arguments)) - u.LogErrorAndExit(schema.CliConfiguration{}, err) + sb.WriteString(fmt.Sprintf("Command requires %d argument(s):\n", len(commandConfig.Arguments))) + for i, arg := range commandConfig.Arguments { + if arg.Name == "" { + u.LogErrorAndExit(schema.CliConfiguration{}, errors.New("invalid argument configuration: empty argument name")) + } + sb.WriteString(fmt.Sprintf(" %d. %s\n", i+1, arg.Name)) + } + if len(args) > 0 { + sb.WriteString(fmt.Sprintf("\nReceived %d argument(s): %s", len(args), strings.Join(args, ", "))) + } + u.LogErrorAndExit(schema.CliConfiguration{}, errors.New(sb.String())) } // no "steps" means a sub command should be specified