2019-12-05 22:35:25 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
2019-12-10 00:25:47 +00:00
|
|
|
"fmt"
|
2020-01-16 21:50:04 +00:00
|
|
|
"github.com/pelotech/drone-helm3/internal/env"
|
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 {
|
2020-01-17 18:13:53 +00:00
|
|
|
*config
|
|
|
|
helmCommand string
|
2019-12-26 20:23:56 +00:00
|
|
|
cmd cmd
|
2019-12-09 17:56:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 21:50:04 +00:00
|
|
|
// NewHelp creates a Help using fields from the given Config. No validation is performed at this time.
|
|
|
|
func NewHelp(cfg env.Config) *Help {
|
|
|
|
return &Help{
|
2020-01-17 18:13:53 +00:00
|
|
|
config: newConfig(cfg),
|
|
|
|
helmCommand: cfg.Command,
|
2020-01-16 21:50:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
// Execute executes the `helm help` command.
|
2020-01-16 23:30:21 +00:00
|
|
|
func (h *Help) Execute() error {
|
2019-12-26 19:29:33 +00:00
|
|
|
if err := h.cmd.Run(); err != nil {
|
|
|
|
return fmt.Errorf("while running '%s': %w", h.cmd.String(), err)
|
|
|
|
}
|
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
if h.helmCommand == "help" {
|
2019-12-26 19:29:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-01-17 18:13:53 +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.
|
2020-01-17 18:13:53 +00:00
|
|
|
func (h *Help) Prepare() error {
|
2020-01-17 19:12:53 +00:00
|
|
|
args := h.globalFlags()
|
|
|
|
args = append(args, "help")
|
2019-12-05 22:35:25 +00:00
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
h.cmd = command(helmBin, args...)
|
2020-01-17 18:13:53 +00:00
|
|
|
h.cmd.Stdout(h.stdout)
|
|
|
|
h.cmd.Stderr(h.stderr)
|
2019-12-05 22:35:25 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
if h.debug {
|
|
|
|
fmt.Fprintf(h.stderr, "Generated command: '%s'\n", h.cmd.String())
|
2019-12-10 00:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2019-12-05 22:35:25 +00:00
|
|
|
}
|