Skip to content

Commit f4bae25

Browse files
committed
Add env var for --context flag
1 parent c5d10a3 commit f4bae25

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,15 @@ Examples:
163163
# Read the flag usage below for more information on --normalize-manifests.",
164164
HELM_DIFF_NORMALIZE_MANIFESTS=true helm diff upgrade my-release datadog/datadog",
165165
166+
# Set HELM_DIFF_OUTPUT_CONTEXT=n to configure the output context to n lines.
167+
# This is equivalent to specifying the --context flag.
168+
# Read the flag usage below for more information on --context.
169+
HELM_DIFF_OUTPUT_CONTEXT=5 helm diff upgrade my-release datadog/datadog
170+
166171
Flags:
167172
--allow-unreleased enables diffing of releases that are not yet deployed via Helm
168173
-a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions
169-
-C, --context int output NUM lines of context around changes (default -1)
174+
-C, --context int output NUM lines of context around changes (default -1), or use HELM_DIFF_OUTPUT_CONTEXT=num
170175
--detailed-exitcode return a non-zero exit code when there are changes
171176
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
172177
--disable-openapi-validation disables rendered templates validation against the Kubernetes OpenAPI Schema

cmd/upgrade.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log"
88
"os"
9+
"strconv"
910
"strings"
1011

1112
jsoniterator "github.com/json-iterator/go"
@@ -112,6 +113,11 @@ func newChartCommand() *cobra.Command {
112113
" # This is equivalent to specifying the --normalize-manifests flag.",
113114
" # Read the flag usage below for more information on --normalize-manifests.",
114115
" HELM_DIFF_NORMALIZE_MANIFESTS=true helm diff upgrade my-release datadog/datadog",
116+
"",
117+
"# Set HELM_DIFF_OUTPUT_CONTEXT=n to configure the output context to n lines.",
118+
"# This is equivalent to specifying the --context flag.",
119+
"# Read the flag usage below for more information on --context.",
120+
"HELM_DIFF_OUTPUT_CONTEXT=5 helm diff upgrade my-release datadog/datadog",
115121
}, "\n"),
116122
Args: func(cmd *cobra.Command, args []string) error {
117123
return checkArgsLength(len(args), "release name", "chart path")
@@ -144,6 +150,16 @@ func newChartCommand() *cobra.Command {
144150
}
145151
}
146152

153+
if diff.OutputContext == -1 && !cmd.Flags().Changed("context") {
154+
contextEnvVar := os.Getenv("HELM_DIFF_OUTPUT_CONTEXT")
155+
if contextEnvVar != "" {
156+
context, err := strconv.Atoi(contextEnvVar)
157+
if err == nil {
158+
diff.OutputContext = context
159+
}
160+
}
161+
}
162+
147163
ProcessDiffOptions(cmd.Flags(), &diff.Options)
148164

149165
diff.release = args[0]

0 commit comments

Comments
 (0)