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
|
// Expect the plan to go off the rails
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
|
||||||
// Throw away the plan
|
// Throw away the plan
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ func determineSteps(cfg Config) *func(Config) []Step {
|
||||||
case "delete":
|
case "delete":
|
||||||
return &uninstall
|
return &uninstall
|
||||||
default:
|
default:
|
||||||
panic("not implemented")
|
return &help
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,9 @@ var lint = func(cfg Config) []Step {
|
||||||
}
|
}
|
||||||
|
|
||||||
var help = func(cfg Config) []Step {
|
var help = func(cfg Config) []Step {
|
||||||
help := &run.Help{}
|
help := &run.Help{
|
||||||
|
HelmCommand: cfg.Command,
|
||||||
|
}
|
||||||
return []Step{help}
|
return []Step{help}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,20 @@ import (
|
||||||
|
|
||||||
// Help is a step in a helm Plan that calls `helm help`.
|
// Help is a step in a helm Plan that calls `helm help`.
|
||||||
type Help struct {
|
type Help struct {
|
||||||
|
HelmCommand string
|
||||||
cmd cmd
|
cmd cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute executes the `helm help` command.
|
// Execute executes the `helm help` command.
|
||||||
func (h *Help) Execute(_ Config) error {
|
func (h *Help) Execute(cfg Config) error {
|
||||||
return h.cmd.Run()
|
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.
|
// Prepare gets the Help ready to execute.
|
||||||
|
|
|
@ -38,9 +38,6 @@ func (suite *HelpTestSuite) TestPrepare() {
|
||||||
Stdout(&stdout)
|
Stdout(&stdout)
|
||||||
mCmd.EXPECT().
|
mCmd.EXPECT().
|
||||||
Stderr(&stderr)
|
Stderr(&stderr)
|
||||||
mCmd.EXPECT().
|
|
||||||
Run().
|
|
||||||
Times(1)
|
|
||||||
|
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Stdout: &stdout,
|
Stdout: &stdout,
|
||||||
|
@ -49,8 +46,32 @@ func (suite *HelpTestSuite) TestPrepare() {
|
||||||
|
|
||||||
h := Help{}
|
h := Help{}
|
||||||
err := h.Prepare(cfg)
|
err := h.Prepare(cfg)
|
||||||
suite.Require().Nil(err)
|
suite.NoError(err)
|
||||||
h.Execute(cfg)
|
}
|
||||||
|
|
||||||
|
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() {
|
func (suite *HelpTestSuite) TestPrepareDebugFlag() {
|
||||||
|
|
Loading…
Reference in a new issue