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

improve custom command error message for missing arguments #752

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Changes from 2 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: 6 additions & 3 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"encoding/json"
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -164,11 +165,13 @@ func preCustomCommand(
parentCommand *cobra.Command,
commandConfig *schema.Command,
) {
var err error

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)
errMsg := fmt.Sprintf("This command needs %d argument(s):", len(commandConfig.Arguments))
for _, arg := range commandConfig.Arguments {
errMsg = fmt.Sprintf("%s %s", errMsg, arg.Name)
}
u.LogErrorAndExit(schema.CliConfiguration{}, errors.New(errMsg))
pkbhowmick marked this conversation as resolved.
Show resolved Hide resolved
}

// no "steps" means a sub command should be specified
Expand Down
Loading