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

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

parent ef4da356
package main package main
import ( import (
"fmt"
"os" "os"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
...@@ -44,3 +46,14 @@ func init() { ...@@ -44,3 +46,14 @@ func init() {
func main() { func main() {
RootCommand.Execute() 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{ ...@@ -34,8 +34,8 @@ var repoListCmd = &cobra.Command{
} }
func runRepoAdd(cmd *cobra.Command, args []string) error { func runRepoAdd(cmd *cobra.Command, args []string) error {
if len(args) != 2 { if err := checkArgsLength(2, len(args), "name for the chart repository", "the url of the chart repository"); err != nil {
return fmt.Errorf("This command needs two argument, a name for the chart repository and the url of the chart repository") return err
} }
err := insertRepoLine(args[0], args[1]) 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