Merge pull request #38 from pelotech/help-by-default
Run the help step by default
This commit is contained in:
commit
29ee0c53ab
|
@ -27,7 +27,7 @@ func main() {
|
|||
|
||||
// Expect the plan to go off the rails
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
|
||||
// Throw away the plan
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func determineSteps(cfg Config) *func(Config) []Step {
|
|||
case "delete":
|
||||
return &uninstall
|
||||
default:
|
||||
panic("not implemented")
|
||||
return &help
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,9 @@ var lint = func(cfg Config) []Step {
|
|||
}
|
||||
|
||||
var help = func(cfg Config) []Step {
|
||||
help := &run.Help{}
|
||||
help := &run.Help{
|
||||
HelmCommand: cfg.Command,
|
||||
}
|
||||
return []Step{help}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,20 @@ import (
|
|||
|
||||
// Help is a step in a helm Plan that calls `helm help`.
|
||||
type Help struct {
|
||||
cmd cmd
|
||||
HelmCommand string
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// Execute executes the `helm help` command.
|
||||
func (h *Help) Execute(_ Config) error {
|
||||
return h.cmd.Run()
|
||||
func (h *Help) Execute(cfg Config) error {
|
||||
if err := h.cmd.Run(); err != nil {
|
||||
return fmt.Errorf("while running '%s': %w", h.cmd.String(), err)
|
||||
}
|
||||
|
||||
if h.HelmCommand == "help" {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown command '%s'", h.HelmCommand)
|
||||
}
|
||||
|
||||
// Prepare gets the Help ready to execute.
|
||||
|
|
|
@ -38,9 +38,6 @@ func (suite *HelpTestSuite) TestPrepare() {
|
|||
Stdout(&stdout)
|
||||
mCmd.EXPECT().
|
||||
Stderr(&stderr)
|
||||
mCmd.EXPECT().
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
cfg := Config{
|
||||
Stdout: &stdout,
|
||||
|
@ -49,8 +46,32 @@ func (suite *HelpTestSuite) TestPrepare() {
|
|||
|
||||
h := Help{}
|
||||
err := h.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
h.Execute(cfg)
|
||||
suite.NoError(err)
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestExecute() {
|
||||
ctrl := gomock.NewController(suite.T())
|
||||
defer ctrl.Finish()
|
||||
mCmd := NewMockcmd(ctrl)
|
||||
originalCommand := command
|
||||
command = func(_ string, _ ...string) cmd {
|
||||
return mCmd
|
||||
}
|
||||
defer func() { command = originalCommand }()
|
||||
|
||||
mCmd.EXPECT().
|
||||
Run().
|
||||
Times(2)
|
||||
|
||||
cfg := Config{}
|
||||
help := Help{
|
||||
HelmCommand: "help",
|
||||
cmd: mCmd,
|
||||
}
|
||||
suite.NoError(help.Execute(cfg))
|
||||
|
||||
help.HelmCommand = "get down on friday"
|
||||
suite.EqualError(help.Execute(cfg), "unknown command 'get down on friday'")
|
||||
}
|
||||
|
||||
func (suite *HelpTestSuite) TestPrepareDebugFlag() {
|
||||
|
|
Loading…
Reference in a new issue