Commit 4899faa9 authored by Brian's avatar Brian Committed by GitHub

Merge pull request #1394 from fibonacci1729/fix/1357

fix(1357): print help text if revision is not specified
parents 08a488f5 0daf3e47
...@@ -19,6 +19,7 @@ package main ...@@ -19,6 +19,7 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"strconv"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -32,7 +33,7 @@ The argument of the rollback command is the name of a release. ...@@ -32,7 +33,7 @@ The argument of the rollback command is the name of a release.
type rollbackCmd struct { type rollbackCmd struct {
name string name string
version int32 revision int32
dryRun bool dryRun bool
disableHooks bool disableHooks bool
out io.Writer out io.Writer
...@@ -51,17 +52,24 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command { ...@@ -51,17 +52,24 @@ 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(len(args), "release name"); err != nil { if err := checkArgsLength(len(args), "release name", "revision number"); err != nil {
return err return err
} }
rollback.name = args[0] rollback.name = args[0]
v64, err := strconv.ParseInt(args[1], 10, 32)
if err != nil {
return fmt.Errorf("invalid revision number '%q': %s", args[1], err)
}
rollback.revision = int32(v64)
rollback.client = ensureHelmClient(rollback.client) rollback.client = ensureHelmClient(rollback.client)
return rollback.run() return rollback.run()
}, },
} }
f := cmd.Flags() f := cmd.Flags()
f.Int32Var(&rollback.version, "revision", 0, "revision to deploy")
f.BoolVar(&rollback.dryRun, "dry-run", false, "simulate a rollback") f.BoolVar(&rollback.dryRun, "dry-run", false, "simulate a rollback")
f.BoolVar(&rollback.disableHooks, "no-hooks", false, "prevent hooks from running during rollback") f.BoolVar(&rollback.disableHooks, "no-hooks", false, "prevent hooks from running during rollback")
...@@ -73,7 +81,7 @@ func (r *rollbackCmd) run() error { ...@@ -73,7 +81,7 @@ func (r *rollbackCmd) run() error {
r.name, r.name,
helm.RollbackDryRun(r.dryRun), helm.RollbackDryRun(r.dryRun),
helm.RollbackDisableHooks(r.disableHooks), helm.RollbackDisableHooks(r.disableHooks),
helm.RollbackVersion(r.version), helm.RollbackVersion(r.revision),
) )
if err != nil { if err != nil {
return prettyError(err) return prettyError(err)
......
...@@ -28,14 +28,13 @@ func TestRollbackCmd(t *testing.T) { ...@@ -28,14 +28,13 @@ func TestRollbackCmd(t *testing.T) {
tests := []releaseCase{ tests := []releaseCase{
{ {
name: "rollback a release", name: "rollback a release",
args: []string{"funny-honey"}, args: []string{"funny-honey", "1"},
flags: []string{"revision", "1"},
expected: "Rollback was a success! Happy Helming!", expected: "Rollback was a success! Happy Helming!",
}, },
{ {
name: "rollback a release without version", name: "rollback a release without revision",
args: []string{"funny-honey"}, args: []string{"funny-honey"},
expected: "Rollback was a success! Happy Helming!", err: true,
}, },
} }
......
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