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

pull/631/head
Michelle Noorali 9 years ago
parent ef4da35607
commit 66477e0598

@ -1,7 +1,9 @@
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])

Loading…
Cancel
Save