diff --git a/main.go b/main.go index 7cbcbcf8..80de8c24 100644 --- a/main.go +++ b/main.go @@ -187,6 +187,11 @@ func main() { Value: 0, Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", }, + cli.IntFlag{ + Name: "context", + Value: 0, + Usage: "output NUM lines of context around changes", + }, }, Action: action(func(run *app.App, c configImpl) error { return run.Diff(c) @@ -290,6 +295,11 @@ func main() { Value: 0, Usage: "maximum number of concurrent helm processes to run, 0 is unlimited", }, + cli.IntFlag{ + Name: "context", + Value: 0, + Usage: "output NUM lines of context around changes", + }, cli.StringFlag{ Name: "args", Value: "", @@ -545,6 +555,10 @@ func (c configImpl) NoColor() bool { return c.c.GlobalBool("no-color") } +func (c configImpl) Context() int { + return c.c.Int("context") +} + func (c configImpl) Logger() *zap.SugaredLogger { return c.c.App.Metadata["logger"].(*zap.SugaredLogger) } diff --git a/pkg/app/config.go b/pkg/app/config.go index f6df1ed7..6e12cdf5 100644 --- a/pkg/app/config.go +++ b/pkg/app/config.go @@ -41,6 +41,7 @@ type ApplyConfigProvider interface { SuppressSecrets() bool NoColor() bool + Context() int concurrencyConfig interactive @@ -67,6 +68,7 @@ type DiffConfigProvider interface { DetailedExitcode() bool NoColor() bool + Context() int concurrencyConfig } diff --git a/pkg/app/run.go b/pkg/app/run.go index 46d405cb..45ec8aa6 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -139,6 +139,7 @@ func (r *Run) Apply(c ApplyConfigProvider) []error { diffOpts := &state.DiffOpts{ NoColor: c.NoColor(), + Context: c.Context(), } releases, errs := st.DiffReleases(helm, c.Values(), c.Concurrency(), detailedExitCode, c.SuppressSecrets(), false, diffOpts) diff --git a/pkg/state/state.go b/pkg/state/state.go index fce77d0e..cb402201 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -776,6 +776,10 @@ func (st *HelmState) prepareDiffReleases(helm helmexec.Interface, additionalValu flags = append(flags, "--no-color") } + if opts.Context > 0 { + flags = append(flags, "--context", fmt.Sprintf("%d", opts.Context)) + } + if len(errs) > 0 { rsErrs := make([]*ReleaseError, len(errs)) for i, e := range errs { @@ -823,6 +827,7 @@ func (st *HelmState) createHelmContext(spec *ReleaseSpec, workerIndex int) helme type DiffOpts struct { NoColor bool + Context int } func (o *DiffOpts) Apply(opts *DiffOpts) { diff --git a/test/integration/run.sh b/test/integration/run.sh index bfca8bcf..3b16c130 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -63,6 +63,9 @@ bash -c "${helmfile} -f ${dir}/happypath.yaml diff --detailed-exitcode; code="'$ info "Diffing ${dir}/happypath.yaml without color" bash -c "${helmfile} -f ${dir}/happypath.yaml --no-color diff --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff" +info "Diffing ${dir}/happypath.yaml with limited context" +bash -c "${helmfile} -f ${dir}/happypath.yaml diff --context 3 --detailed-exitcode; code="'$?'"; [ "'${code}'" -eq 2 ]" || fail "unexpected exit code returned by helmfile diff" + info "Templating ${dir}/happypath.yaml" ${helmfile} -f ${dir}/happypath.yaml template code=$?