woodpecker-helm3/internal/run/lint.go
Erin Call 79532e7635
Extract the debug/namespace flags into run.Config [#67]
This is a general-purpose cleanup commit; every step except InitKube had
the same six "add the --debug and --namespace flags if applicable" code.
2020-01-17 11:12:53 -08:00

70 lines
1.4 KiB
Go

package run
import (
"fmt"
"github.com/pelotech/drone-helm3/internal/env"
)
// Lint is an execution step that calls `helm lint` when executed.
type Lint struct {
*config
chart string
values string
stringValues string
valuesFiles []string
strict bool
cmd cmd
}
// NewLint creates a Lint using fields from the given Config. No validation is performed at this time.
func NewLint(cfg env.Config) *Lint {
return &Lint{
config: newConfig(cfg),
chart: cfg.Chart,
values: cfg.Values,
stringValues: cfg.StringValues,
valuesFiles: cfg.ValuesFiles,
strict: cfg.LintStrictly,
}
}
// Execute executes the `helm lint` command.
func (l *Lint) Execute() error {
return l.cmd.Run()
}
// Prepare gets the Lint ready to execute.
func (l *Lint) Prepare() error {
if l.chart == "" {
return fmt.Errorf("chart is required")
}
args := l.globalFlags()
args = append(args, "lint")
if l.values != "" {
args = append(args, "--set", l.values)
}
if l.stringValues != "" {
args = append(args, "--set-string", l.stringValues)
}
for _, vFile := range l.valuesFiles {
args = append(args, "--values", vFile)
}
if l.strict {
args = append(args, "--strict")
}
args = append(args, l.chart)
l.cmd = command(helmBin, args...)
l.cmd.Stdout(l.stdout)
l.cmd.Stderr(l.stderr)
if l.debug {
fmt.Fprintf(l.stderr, "Generated command: '%s'\n", l.cmd.String())
}
return nil
}