Skip to content

Commit

Permalink
use string builder
Browse files Browse the repository at this point in the history
Signed-off-by: Pulak Kanti Bhowmick <[email protected]>
  • Loading branch information
pkbhowmick committed Oct 30, 2024
1 parent 873b1ca commit 2ee66a9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,18 @@ func preCustomCommand(
parentCommand *cobra.Command,
commandConfig *schema.Command,
) {

var sb strings.Builder
if len(args) != len(commandConfig.Arguments) {
errMsg := fmt.Sprintf("This command needs %d argument(s):", len(commandConfig.Arguments))
sb.WriteString(fmt.Sprintf("This command needs %d argument(s):", len(commandConfig.Arguments)))
argName := make([]string, 0, len(commandConfig.Arguments))
for _, arg := range commandConfig.Arguments {
errMsg = fmt.Sprintf("%s %s", errMsg, arg.Name)
if arg.Name == "" {
u.LogErrorAndExit(schema.CliConfiguration{}, errors.New("invalid argument configuration: empty argument name"))
}
argName = append(argName, arg.Name)
}
u.LogErrorAndExit(schema.CliConfiguration{}, errors.New(errMsg))
sb.WriteString(fmt.Sprintf(" %s", strings.Join(argName, ", ")))
u.LogErrorAndExit(schema.CliConfiguration{}, errors.New(sb.String()))
}

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

0 comments on commit 2ee66a9

Please sign in to comment.