Commit 990b763
refactor(cli_utils): DRY processArgsAndFlags with table-driven flag parsing, 100% unit test coverage (#2225)
* Initial plan
* refactor(cli_utils): reduce cyclomatic complexity and achieve 100% unit test coverage
- Extract parseFlagValue helper to eliminate 25+ repetitive if/else flag-parsing patterns
- Extract parseIdentityFlag helper for --identity special-case semantics
- Extract parseFromPlanFlag helper for --from-plan optional-value semantics
- Create stringFlagDef table mapping 26 flags to ArgsAndFlagsInfo setters (DRY)
- Consolidate 5 boolean flags into a single switch statement
- Remove dead code branch in parseQuotedCompoundSubcommand
- Fix false-positive prefix matching: strings.HasPrefix(arg+'=',flag) → strings.HasPrefix(arg,flag+'=')
- Add TestParseFlagValue, TestParseIdentityFlag, TestParseFromPlanFlag unit tests
- Add TestProcessArgsAndFlags_AllStringFlagsDefs covering all 26 string flags
- Add TestProcessArgsAndFlags_BooleanFlags for --dry-run, --skip-init, -h, --help, --affected, --all
- Add TestProcessArgsAndFlags_GlobalOptions for both space and equals forms
- Add TestProcessArgsAndFlags_NeedHelp for SubCommand extraction on help flag
- Add TestProcessArgsAndFlags_FromPlan for all --from-plan forms
- Add TestProcessArgsAndFlags_EmptyAfterFlagRemoval edge case
- Add TestProcessArgsAndFlags_IdentityError and TestProcessArgsAndFlags_SingleCommandError
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* chore: address code review, add blog post, roadmap entry, and nitrocode author
- Add defensive check back in parseQuotedCompoundSubcommand (with direct test for coverage)
- Fix naming inconsistency: expectedPlanFile -> wantPlanFile in TestParseFromPlanFlag
- Add nitrocode (RB, CEO @ Infralicious) to website/blog/authors.yml
- Add blog post: 2026-03-18-process-args-flags-refactor.mdx
- Add roadmap milestone to Code Quality initiative for processArgsAndFlags refactor
- Update roadmap description to reflect 2026 quality work
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* [autofix.ci] apply automated fixes
* fix(cli_utils): address all CodeRabbit audit findings
H1/H2: Replace strings.Split with strings.SplitN(arg, "=", 2) in parseFlagValue
- Values containing '=' (JMESPath, key=value pairs, ARN-like strings) now parse correctly
- Before: --query=.tags[?env==prod] would error; after: value is ".tags[?env==prod]"
- parseIdentityFlag simplified to void return (can never error with SplitN)
L1: Add cfg.SettingsListMergeStrategyFlag to commonFlags
- --settings-list-merge-strategy is now stripped from AdditionalArgsAndFlags
- Prevents the flag from leaking through to Terraform/Helmfile as an unknown flag
L2: Fix optional-value flag stripping (--from-plan, --identity)
- --from-plan --refresh=false no longer silently strips --refresh=false from pass-through
- --identity --tf-flag no longer strips the Terraform flag from pass-through
- Only strip i+1 when next arg was actually consumed as the flag's value (not starting with '-')
M1-M4: Add comprehensive tests for all identified coverage gaps
- TestParseFlagValue_EqualsInValue: JMESPath, key=value, multi-equals in values
- TestProcessArgsAndFlags_FlagStripping: all flags strip both name and value
- TestProcessArgsAndFlags_OptionalValueFlagStripping: --from-plan/--identity L2 fix
- TestProcessArgsAndFlags_AllStringFlagsSpaceForm: 8 previously untested flags
- Test_processArgsAndFlags_equalsInValues: all affected flags with '=' values work
Remove/update tests that tested old buggy behavior:
- Test_processArgsAndFlags_errorPaths: remove all "with multiple equals" cases
- Test_processArgsAndFlags_invalidFlag: --init-pass-vars=invalid=true now succeeds
- TestParseFlagValue: "multiple equals errors" -> "value containing = works"
- TestParseIdentityFlag: "multiple equals errors" -> "ARN-style value works"
- TestProcessArgsAndFlags_IdentityError -> TestProcessArgsAndFlags_IdentityWithEqualsInValue
All target functions maintain 100% coverage:
- parseFlagValue: 100%, parseIdentityFlag: 100%, parseFromPlanFlag: 100%
- processArgsAndFlags: 100%, parseQuotedCompoundSubcommand: 100%
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* [autofix.ci] apply automated fixes
* Fix boolean flags stripping adjacent Terraform flags from pass-through args
The stripping loop in processArgsAndFlags unconditionally stripped i+1
for ALL commonFlags entries that weren't --from-plan or --identity.
This silently dropped unrelated Terraform flags (e.g., --refresh=false,
--parallelism=10) when they appeared immediately after a boolean Atmos
flag like --dry-run, --skip-init, --affected, --all, --process-templates,
--process-functions, --heatmap, or --profiler-enabled.
Fix: Introduce valueTakingCommonFlags map derived from stringFlagDefs plus
explicitly enumerated value-taking entries (--stack, -s, --global-options,
--kubeconfig-path, profiler/heatmap/profile string flags, --skip). The
stripping loop now only strips i+1 when the flag is in this set.
Add TestProcessArgsAndFlags_BooleanFlagsDoNotStripNextArg with 6 test
cases covering --dry-run, --skip-init, --affected, --all,
--process-templates, and --process-functions.
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* Changes before error encountered
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
* fix: audit processArgsAndFlags refactor — bounds check, tests, and fix doc
- Add bounds check to valueTakingCommonFlags stripping (i+1 OOB guard)
- Fix gosec G602 slice index warning in optional-value flag stripping
- Fix godot linter warnings in pre-existing comments
- Add TestFlagListConsistency to validate three parallel flag lists stay in sync
- Add TestProcessArgsAndFlags_PrefixCollisionSafety for --skip/--heatmap/--profile
- Add TestProcessArgsAndFlags_BooleanFlagEqualsFormStripping for equals-form booleans
- Add TestProcessArgsAndFlags_GlobalOptionsStripping for pass-through arg verification
- Add fix doc documenting all 8 audit findings
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* update docs
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andriy Knysh <aknysh@users.noreply.github.com>
Co-authored-by: aknysh <andriy.knysh@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 0ef4161 commit 990b763
File tree
7 files changed
+1839
-553
lines changed- docs/fixes
- internal/exec
- website
- blog
- src/data
7 files changed
+1839
-553
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
0 commit comments