MCPcopy
hub / github.com/helm/helm / cmdGetDryRunFlagStrategy

Function cmdGetDryRunFlagStrategy

pkg/cmd/helpers.go:45–83  ·  view source on GitHub ↗

Determine the `action.DryRunStrategy` given -dry-run= ` flag (or absence of) Legacy usage of the flag: boolean values, and `--dry-run` (without value) are supported, and log warnings emitted

(cmd *cobra.Command, isTemplate bool)

Source from the content-addressed store, hash-verified

43// Determine the `action.DryRunStrategy` given -dry-run=<value>` flag (or absence of)
44// Legacy usage of the flag: boolean values, and `--dry-run` (without value) are supported, and log warnings emitted
45func cmdGetDryRunFlagStrategy(cmd *cobra.Command, isTemplate bool) (action.DryRunStrategy, error) {
46
47 f := cmd.Flag("dry-run")
48 v := f.Value.String()
49
50 switch v {
51 case f.NoOptDefVal:
52 slog.Warn(`--dry-run is deprecated and should be replaced with '--dry-run=client'`)
53 return action.DryRunClient, nil
54 case string(action.DryRunClient):
55 return action.DryRunClient, nil
56 case string(action.DryRunServer):
57 return action.DryRunServer, nil
58 case string(action.DryRunNone):
59 if isTemplate {
60 // Special case hack for `helm template`, which is always a dry run
61 return action.DryRunNone, fmt.Errorf(`invalid dry-run value (%q). Must be "server" or "client"`, v)
62 }
63 return action.DryRunNone, nil
64 }
65
66 b, err := strconv.ParseBool(v)
67 if err != nil {
68 return action.DryRunNone, fmt.Errorf(`invalid dry-run value (%q). Must be "none", "server", or "client"`, v)
69 }
70
71 if isTemplate && !b {
72 // Special case for `helm template`, which is always a dry run
73 return action.DryRunNone, fmt.Errorf(`invalid dry-run value (%q). Must be "server" or "client"`, v)
74 }
75
76 result := action.DryRunNone
77 if b {
78 result = action.DryRunClient
79 }
80 slog.Warn(fmt.Sprintf(`boolean '--dry-run=%v' flag is deprecated and must be replaced with '--dry-run=%s'`, v, result))
81
82 return result, nil
83}

Callers 5

newInstallCmdFunction · 0.85
newUpgradeCmdFunction · 0.85
newRollbackCmdFunction · 0.85
newTemplateCmdFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…