Skip to content

Add env var for --context flag #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,15 @@ Examples:
# Read the flag usage below for more information on --normalize-manifests.",
HELM_DIFF_NORMALIZE_MANIFESTS=true helm diff upgrade my-release datadog/datadog",

# Set HELM_DIFF_OUTPUT_CONTEXT=n to configure the output context to n lines.
# This is equivalent to specifying the --context flag.
# Read the flag usage below for more information on --context.
HELM_DIFF_OUTPUT_CONTEXT=5 helm diff upgrade my-release datadog/datadog

Flags:
--allow-unreleased enables diffing of releases that are not yet deployed via Helm
-a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions
-C, --context int output NUM lines of context around changes (default -1)
-C, --context int output NUM lines of context around changes (default -1), or use HELM_DIFF_OUTPUT_CONTEXT=num
--detailed-exitcode return a non-zero exit code when there are changes
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
--disable-openapi-validation disables rendered templates validation against the Kubernetes OpenAPI Schema
Expand Down
16 changes: 16 additions & 0 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"strings"

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

if diff.OutputContext == -1 && !cmd.Flags().Changed("context") {
contextEnvVar := os.Getenv("HELM_DIFF_OUTPUT_CONTEXT")
if contextEnvVar != "" {
context, err := strconv.Atoi(contextEnvVar)
if err == nil {
diff.OutputContext = context
}
}
}

ProcessDiffOptions(cmd.Flags(), &diff.Options)

diff.release = args[0]
Expand Down