This fixes the run package's leaky abstraction; other packages no longer need to know or care that run.Config even exists. Note that since the various Steps now depend on having a non-nil pointer to a run.Config, it's unsafe (or at least risky) to initialize them directly. They should be created with their NewSTEPNAME functions. All their fields are now private, to reflect this.
52 lines
1 KiB
Go
52 lines
1 KiB
Go
package run
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/pelotech/drone-helm3/internal/env"
|
|
)
|
|
|
|
// Help is a step in a helm Plan that calls `helm help`.
|
|
type Help struct {
|
|
*config
|
|
helmCommand string
|
|
cmd cmd
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
// Prepare gets the Help ready to execute.
|
|
func (h *Help) Prepare() error {
|
|
args := []string{"help"}
|
|
if h.debug {
|
|
args = append([]string{"--debug"}, args...)
|
|
}
|
|
|
|
h.cmd = command(helmBin, args...)
|
|
h.cmd.Stdout(h.stdout)
|
|
h.cmd.Stderr(h.stderr)
|
|
|
|
if h.debug {
|
|
fmt.Fprintf(h.stderr, "Generated command: '%s'\n", h.cmd.String())
|
|
}
|
|
|
|
return nil
|
|
}
|