From 4617630d9e23ac45b80842e7e2515a447555e008 Mon Sep 17 00:00:00 2001 From: Pulak Kanti Bhowmick Date: Fri, 8 Nov 2024 02:23:14 +0600 Subject: [PATCH] handle invalid command error (#766) Signed-off-by: Pulak Kanti Bhowmick --- cmd/cmd_utils.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index 2477679de..2bdbdb8fb 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -167,6 +167,15 @@ func preCustomCommand( ) { var sb strings.Builder if len(args) != len(commandConfig.Arguments) { + if len(commandConfig.Arguments) == 0 { + u.LogError(schema.CliConfiguration{}, errors.New("invalid command")) + sb.WriteString("Available command(s):\n") + for i, c := range commandConfig.Commands { + sb.WriteString(fmt.Sprintf("%d. %s %s %s\n", i+1, parentCommand.Use, commandConfig.Name, c.Name)) + } + u.LogInfo(schema.CliConfiguration{}, sb.String()) + os.Exit(1) + } sb.WriteString(fmt.Sprintf("Command requires %d argument(s):\n", len(commandConfig.Arguments))) for i, arg := range commandConfig.Arguments { if arg.Name == "" {