()
| 120 | ` |
| 121 | |
| 122 | func newChartCommand() *cobra.Command { |
| 123 | diff := diffCmd{ |
| 124 | namespace: os.Getenv("HELM_NAMESPACE"), |
| 125 | } |
| 126 | unknownFlags := os.Getenv("HELM_DIFF_IGNORE_UNKNOWN_FLAGS") == envTrue |
| 127 | |
| 128 | cmd := &cobra.Command{ |
| 129 | Use: "upgrade [flags] [RELEASE] [CHART]", |
| 130 | Short: "Show a diff explaining what a helm upgrade would change.", |
| 131 | Long: globalUsage, |
| 132 | Example: strings.Join([]string{ |
| 133 | " helm diff upgrade my-release stable/postgresql --values values.yaml", |
| 134 | "", |
| 135 | " # Set HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true to ignore unknown flags", |
| 136 | " # It's useful when you're using `helm-diff` in a `helm upgrade` wrapper.", |
| 137 | " # See https://github.com/databus23/helm-diff/issues/278 for more information.", |
| 138 | " HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true helm diff upgrade my-release stable/postgres --wait", |
| 139 | "", |
| 140 | " # Set HELM_DIFF_USE_UPGRADE_DRY_RUN=true to", |
| 141 | " # use `helm upgrade --dry-run` instead of `helm template` to render manifests from the chart.", |
| 142 | " # See https://github.com/databus23/helm-diff/issues/253 for more information.", |
| 143 | " HELM_DIFF_USE_UPGRADE_DRY_RUN=true helm diff upgrade my-release datadog/datadog", |
| 144 | "", |
| 145 | " # Set HELM_DIFF_THREE_WAY_MERGE=true to", |
| 146 | " # enable the three-way-merge on diff.", |
| 147 | " # This is equivalent to specifying the --three-way-merge flag.", |
| 148 | " # Read the flag usage below for more information on --three-way-merge.", |
| 149 | " HELM_DIFF_THREE_WAY_MERGE=true helm diff upgrade my-release datadog/datadog", |
| 150 | "", |
| 151 | " # Set HELM_DIFF_NORMALIZE_MANIFESTS=true to", |
| 152 | " # normalize the yaml file content when using helm diff.", |
| 153 | " # This is equivalent to specifying the --normalize-manifests flag.", |
| 154 | " # Read the flag usage below for more information on --normalize-manifests.", |
| 155 | " HELM_DIFF_NORMALIZE_MANIFESTS=true helm diff upgrade my-release datadog/datadog", |
| 156 | "", |
| 157 | "# Set HELM_DIFF_OUTPUT_CONTEXT=n to configure the output context to n lines.", |
| 158 | "# This is equivalent to specifying the --context flag.", |
| 159 | "# Read the flag usage below for more information on --context.", |
| 160 | "HELM_DIFF_OUTPUT_CONTEXT=5 helm diff upgrade my-release datadog/datadog", |
| 161 | }, "\n"), |
| 162 | Args: func(cmd *cobra.Command, args []string) error { |
| 163 | return checkArgsLength(len(args), "release name", "chart path") |
| 164 | }, |
| 165 | RunE: func(cmd *cobra.Command, args []string) error { |
| 166 | if diff.dryRunMode == "" { |
| 167 | diff.dryRunMode = dryRunNone |
| 168 | } else if !slices.Contains(validDryRunValues, diff.dryRunMode) { |
| 169 | return fmt.Errorf("flag %q must take a bool value or either %q or %q, but got %q", "dry-run", dryRunNoOptDefVal, dryRunServer, diff.dryRunMode) |
| 170 | } |
| 171 | |
| 172 | if !slices.Contains(validServerSideVals, diff.serverSide) { |
| 173 | return fmt.Errorf("flag %q must be %q, %q or %q, but got %q", "server-side", envTrue, envFalse, serverSideAuto, diff.serverSide) |
| 174 | } |
| 175 | |
| 176 | // Suppress the command usage on error. See #77 for more info |
| 177 | cmd.SilenceUsage = true |
| 178 | |
| 179 | // See https://github.com/databus23/helm-diff/issues/253 |
no test coverage detected