Skip to content

Commit

Permalink
fix(1357): print help text if revision is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci1729 committed Oct 18, 2016
1 parent d744a3d commit 0daf3e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 12 additions & 4 deletions cmd/helm/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"
"io"
"strconv"

"github.com/spf13/cobra"

Expand All @@ -32,7 +33,7 @@ The argument of the rollback command is the name of a release.

type rollbackCmd struct {
name string
version int32
revision int32
dryRun bool
disableHooks bool
out io.Writer
Expand All @@ -51,17 +52,24 @@ 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(len(args), "release name"); err != nil {
if err := checkArgsLength(len(args), "release name", "revision number"); err != nil {
return err
}

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)
return rollback.run()
},
}

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.disableHooks, "no-hooks", false, "prevent hooks from running during rollback")

Expand All @@ -73,7 +81,7 @@ func (r *rollbackCmd) run() error {
r.name,
helm.RollbackDryRun(r.dryRun),
helm.RollbackDisableHooks(r.disableHooks),
helm.RollbackVersion(r.version),
helm.RollbackVersion(r.revision),
)
if err != nil {
return prettyError(err)
Expand Down
9 changes: 4 additions & 5 deletions cmd/helm/rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ func TestRollbackCmd(t *testing.T) {
tests := []releaseCase{
{
name: "rollback a release",
args: []string{"funny-honey"},
flags: []string{"revision", "1"},
args: []string{"funny-honey", "1"},
expected: "Rollback was a success! Happy Helming!",
},
{
name: "rollback a release without version",
args: []string{"funny-honey"},
expected: "Rollback was a success! Happy Helming!",
name: "rollback a release without revision",
args: []string{"funny-honey"},
err: true,
},
}

Expand Down

0 comments on commit 0daf3e4

Please sign in to comment.