woodpecker-helm3/internal/run/help.go

50 lines
1 KiB
Go
Raw Permalink Normal View History

2019-12-05 22:35:25 +00:00
package run
import (
"fmt"
"github.com/pelotech/drone-helm3/internal/env"
2019-12-05 22:35:25 +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 {
*config
helmCommand string
cmd cmd
2019-12-09 17:56:02 +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{
config: newConfig(cfg),
helmCommand: cfg.Command,
}
}
// Execute executes the `helm help` command.
func (h *Help) Execute() 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)
2019-12-09 17:56:02 +00:00
}
// Prepare gets the Help ready to execute.
func (h *Help) Prepare() error {
args := h.globalFlags()
args = append(args, "help")
2019-12-05 22:35:25 +00:00
h.cmd = command(helmBin, args...)
h.cmd.Stdout(h.stdout)
h.cmd.Stderr(h.stderr)
2019-12-05 22:35:25 +00:00
if h.debug {
fmt.Fprintf(h.stderr, "Generated command: '%s'\n", h.cmd.String())
}
return nil
2019-12-05 22:35:25 +00:00
}