Commit 0a9d455
committed
fix: reset shared rootCmd flag state between tests
`rootCmd`` is a package-level variable in interal/cli/root.go, shared across all tests
in the cli package.
Cobra does not reset flag values or their Changed
state between `Execute()` calls, so a flag set by one test leaks into the
next.
This commit adds a `resetCmd` helper that recursively walks the command tree and
restores each flag to its default value and `Changed=false`.
Let's call it at the start of each test that invokes `rootCmd.Execute()`.1 parent d70af89 commit 0a9d455
1 file changed
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
13 | 29 | | |
14 | 30 | | |
15 | 31 | | |
| |||
36 | 52 | | |
37 | 53 | | |
38 | 54 | | |
| 55 | + | |
39 | 56 | | |
40 | 57 | | |
41 | 58 | | |
| |||
58 | 75 | | |
59 | 76 | | |
60 | 77 | | |
| 78 | + | |
61 | 79 | | |
62 | 80 | | |
63 | 81 | | |
| |||
96 | 114 | | |
97 | 115 | | |
98 | 116 | | |
| 117 | + | |
99 | 118 | | |
100 | 119 | | |
101 | 120 | | |
| |||
125 | 144 | | |
126 | 145 | | |
127 | 146 | | |
| 147 | + | |
128 | 148 | | |
129 | 149 | | |
130 | 150 | | |
| |||
141 | 161 | | |
142 | 162 | | |
143 | 163 | | |
| 164 | + | |
144 | 165 | | |
145 | 166 | | |
146 | 167 | | |
| |||
172 | 193 | | |
173 | 194 | | |
174 | 195 | | |
| 196 | + | |
175 | 197 | | |
176 | 198 | | |
177 | 199 | | |
| |||
0 commit comments