Implement the debug flag and help command

I'm vacillating about the choice to have separate Config structs in the
`helm` and `run` packages. I can't tell whether it's "good separation of
concerns" or "cumbersome and over-engineered." It seems appropriate at
the moment, though.
This commit is contained in:
Erin Call
2019-12-09 16:25:47 -08:00
parent 446c6f1761
commit 4cbb4922fb
8 changed files with 260 additions and 63 deletions

View File

@@ -1,7 +1,7 @@
package run
import (
"os"
"fmt"
)
// Help is a step in a helm Plan that calls `helm help`.
@@ -9,18 +9,25 @@ type Help struct {
cmd cmd
}
// Run launches the command.
func (h *Help) Run() error {
// Execute executes the `helm help` command.
func (h *Help) Execute() error {
return h.cmd.Run()
}
// NewHelp returns a new Help.
func NewHelp() *Help {
h := Help{}
// 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...)
}
h.cmd = command(helmBin, "help")
h.cmd.Stdout(os.Stdout)
h.cmd.Stderr(os.Stderr)
h.cmd = command(helmBin, args...)
h.cmd.Stdout(cfg.Stdout)
h.cmd.Stderr(cfg.Stderr)
return &h
if cfg.Debug {
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", h.cmd.String())
}
return nil
}