Commit 66477e05 authored by Michelle Noorali's avatar Michelle Noorali

ref(helm): add helper to check len of cmd args

parent ef4da356
package main
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
......@@ -44,3 +46,14 @@ func init() {
func main() {
RootCommand.Execute()
}
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
if actualNum != expectedNum {
arg := "arguments"
if expectedNum == 1 {
arg = "argument"
}
return fmt.Errorf("This command needs %v %s: %s", expectedNum, arg, strings.Join(requiredArgs, ", "))
}
return nil
}
......@@ -34,8 +34,8 @@ var repoListCmd = &cobra.Command{
}
func runRepoAdd(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
return fmt.Errorf("This command needs two argument, a name for the chart repository and the url of the chart repository")
if err := checkArgsLength(2, len(args), "name for the chart repository", "the url of the chart repository"); err != nil {
return err
}
err := insertRepoLine(args[0], args[1])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment