ref(helm): refactor checkArgsLength method

pull/1181/head
Michelle Noorali 8 years ago
parent 60b4188867
commit e50f9e6b24

@ -138,8 +138,9 @@ func teardown() {
} }
} }
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error { func checkArgsLength(argsReceived int, requiredArgs ...string) error {
if actualNum != expectedNum { expectedNum := len(requiredArgs)
if argsReceived != expectedNum {
arg := "arguments" arg := "arguments"
if expectedNum == 1 { if expectedNum == 1 {
arg = "argument" arg = "argument"

@ -70,7 +70,7 @@ func newInspectCmd(c helm.Interface, out io.Writer) *cobra.Command {
Short: "inspect a chart", Short: "inspect a chart",
Long: inspectDesc, Long: inspectDesc,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(1, len(args), "chart name"); err != nil { if err := checkArgsLength(len(args), "chart name"); err != nil {
return err return err
} }
cp, err := locateChartPath(args[0], insp.verify, insp.keyring) cp, err := locateChartPath(args[0], insp.verify, insp.keyring)

@ -89,7 +89,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
Long: installDesc, Long: installDesc,
PersistentPreRunE: setupConnection, PersistentPreRunE: setupConnection,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(1, len(args), "chart name"); err != nil { if err := checkArgsLength(len(args), "chart name"); err != nil {
return err return err
} }
cp, err := locateChartPath(args[0], inst.verify, inst.keyring) cp, err := locateChartPath(args[0], inst.verify, inst.keyring)

@ -69,7 +69,7 @@ var repoIndexCmd = &cobra.Command{
} }
func runRepoAdd(cmd *cobra.Command, args []string) error { func runRepoAdd(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(2, len(args), "name for the chart repository", "the url of the chart repository"); err != nil { if err := checkArgsLength(len(args), "name for the chart repository", "the url of the chart repository"); err != nil {
return err return err
} }
name, url := args[0], args[1] name, url := args[0], args[1]
@ -101,7 +101,7 @@ func runRepoList(cmd *cobra.Command, args []string) error {
} }
func runRepoRemove(cmd *cobra.Command, args []string) error { func runRepoRemove(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(1, len(args), "name of chart repository"); err != nil { if err := checkArgsLength(len(args), "name of chart repository"); err != nil {
return err return err
} }
return removeRepoLine(args[0]) return removeRepoLine(args[0])

@ -52,7 +52,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
Long: rollbackDesc, Long: rollbackDesc,
PersistentPreRunE: setupConnection, PersistentPreRunE: setupConnection,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(1, len(args), "release name"); err != nil { if err := checkArgsLength(len(args), "release name"); err != nil {
return err return err
} }
rollback.client = ensureHelmClient(rollback.client) rollback.client = ensureHelmClient(rollback.client)

@ -64,7 +64,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
Long: upgradeDesc, Long: upgradeDesc,
PersistentPreRunE: setupConnection, PersistentPreRunE: setupConnection,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if err := checkArgsLength(2, len(args), "release name, chart path"); err != nil { if err := checkArgsLength(len(args), "release name", "chart path"); err != nil {
return err return err
} }

Loading…
Cancel
Save