Commit e50f9e6b authored by Michelle Noorali's avatar Michelle Noorali

ref(helm): refactor checkArgsLength method

parent 60b41888
......@@ -138,8 +138,9 @@ func teardown() {
}
}
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
if actualNum != expectedNum {
func checkArgsLength(argsReceived int, requiredArgs ...string) error {
expectedNum := len(requiredArgs)
if argsReceived != expectedNum {
arg := "arguments"
if expectedNum == 1 {
arg = "argument"
......
......@@ -70,7 +70,7 @@ func newInspectCmd(c helm.Interface, out io.Writer) *cobra.Command {
Short: "inspect a chart",
Long: inspectDesc,
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
}
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,
PersistentPreRunE: setupConnection,
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
}
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 {
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
}
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 {
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 removeRepoLine(args[0])
......
......@@ -52,7 +52,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
Long: rollbackDesc,
PersistentPreRunE: setupConnection,
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
}
rollback.client = ensureHelmClient(rollback.client)
......
......@@ -64,7 +64,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
Long: upgradeDesc,
PersistentPreRunE: setupConnection,
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
}
......
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