Return an error on unknown commands [#15]

I'm probably overthinking this--explicitly calling help is a strange and
unusual case--but it doesn't really hurt, so I'm going for it.
This commit is contained in:
Erin Call
2019-12-26 11:29:33 -08:00
parent 34b9ec1c4c
commit 6d28b7b28a
5 changed files with 39 additions and 14 deletions

View File

@@ -10,8 +10,15 @@ type Help struct {
}
// 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 cfg.HelmCommand == "help" {
return nil
}
return fmt.Errorf("unknown command '%s'", cfg.HelmCommand)
}
// Prepare gets the Help ready to execute.