2019-12-05 22:35:25 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
2019-12-10 00:25:47 +00:00
|
|
|
"fmt"
|
2019-12-05 22:35:25 +00:00
|
|
|
)
|
|
|
|
|
2019-12-09 18:52:41 +00:00
|
|
|
// Help is a step in a helm Plan that calls `helm help`.
|
2019-12-09 17:56:02 +00:00
|
|
|
type Help struct {
|
2019-12-26 20:23:56 +00:00
|
|
|
HelmCommand string
|
|
|
|
cmd cmd
|
2019-12-09 17:56:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
// Execute executes the `helm help` command.
|
2019-12-26 19:29:33 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-12-26 20:23:56 +00:00
|
|
|
if h.HelmCommand == "help" {
|
2019-12-26 19:29:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
2019-12-26 20:23:56 +00:00
|
|
|
return fmt.Errorf("unknown command '%s'", h.HelmCommand)
|
2019-12-09 17:56:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
// Prepare gets the Help ready to execute.
|
|
|
|
func (h *Help) Prepare(cfg Config) error {
|
|
|
|
args := []string{"help"}
|
|
|
|
if cfg.Debug {
|
|
|
|
args = append([]string{"--debug"}, args...)
|
|
|
|
}
|
2019-12-05 22:35:25 +00:00
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
h.cmd = command(helmBin, args...)
|
|
|
|
h.cmd.Stdout(cfg.Stdout)
|
|
|
|
h.cmd.Stderr(cfg.Stderr)
|
2019-12-05 22:35:25 +00:00
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
if cfg.Debug {
|
|
|
|
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", h.cmd.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2019-12-05 22:35:25 +00:00
|
|
|
}
|