Commit 85562b1
authored
refactor(cmd): inline trivial getDefault* env-wrapper functions (#3894)
13 `getDefault*` functions across `flags_logging.go`, `flags_difc.go`,
and `flags_tracing.go` were pure one-liner delegates to
`envutil.GetEnv{String,Int,Bool}` — ~30 lines of boilerplate with no
abstraction value.
## Changes
- **Inlined 12 wrapper functions** directly at their single call sites
in `RegisterFlag` blocks and `proxy.go`/`root.go`:
```go
// Before
cmd.Flags().StringVar(&logDir, "log-dir", getDefaultLogDir(), "...")
// After
cmd.Flags().StringVar(&logDir, "log-dir",
envutil.GetEnvString("MCP_GATEWAY_LOG_DIR", config.DefaultLogDir),
"...")
```
- **Preserved `getDefaultDIFCMode()`** — retains validation logic (case
normalisation + `difc.ParseEnforcementMode` check) that exceeds a simple
env lookup
- **Removed unused constants** `defaultPayloadPathPrefix` and
`defaultAllowOnlyMinIntegrity` (both were `""`)
- **Added `envutil` import to `root.go`** to support the inlined
`GetEnvBool` call
- **Updated `flags.go` package comment** to document the new inline
convention and note the `getDefaultDIFCMode` exception
- **Removed/trimmed test functions** that exclusively tested the deleted
helpers (`flags_logging_test.go` deleted entirely;
`flags_tracing_test.go`, `flags_difc_test.go`, `proxy_test.go` trimmed)
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build3838746122/b514/launcher.test
/tmp/go-build3838746122/b514/launcher.test
-test.testlogfile=/tmp/go-build3838746122/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -I .cfg
qaJP/faPO1YLymyA-ifaceassert x_amd64/vet --gdwarf-5 l -o x_amd64/vet
.cfg�� -I ylov/l0IgnnYtDUbmqPCsylov x_amd64/vet . --gdwarf2 --64
x_amd64/vet` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3838746122/b496/config.test
/tmp/go-build3838746122/b496/config.test
-test.testlogfile=/tmp/go-build3838746122/b496/testlog.txt
-test.paniconexit0 -test.timeout=10m0s
/tmp/go-build3838746122/b398/vet.cfg g_.a 1866238/b288/ x_amd64/vet -I
ernal/launcher -imultiarch x_amd64/vet 1866�� .cfg
/tmp/go-build131-ifaceassert 64/pkg/tool/linu-nilfunc . --gdwarf2 --64
64/pkg/tool/linu-buildtags` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build3838746122/b514/launcher.test
/tmp/go-build3838746122/b514/launcher.test
-test.testlogfile=/tmp/go-build3838746122/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -I .cfg
qaJP/faPO1YLymyA-ifaceassert x_amd64/vet --gdwarf-5 l -o x_amd64/vet
.cfg�� -I ylov/l0IgnnYtDUbmqPCsylov x_amd64/vet . --gdwarf2 --64
x_amd64/vet` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build3838746122/b514/launcher.test
/tmp/go-build3838746122/b514/launcher.test
-test.testlogfile=/tmp/go-build3838746122/b514/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -I .cfg
qaJP/faPO1YLymyA-ifaceassert x_amd64/vet --gdwarf-5 l -o x_amd64/vet
.cfg�� -I ylov/l0IgnnYtDUbmqPCsylov x_amd64/vet . --gdwarf2 --64
x_amd64/vet` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build3838746122/b523/mcp.test
/tmp/go-build3838746122/b523/mcp.test
-test.testlogfile=/tmp/go-build3838746122/b523/testlog.txt
-test.paniconexit0 -test.timeout=10m0s .cfg�� akF0/nz7G04-4df3VsO6SakF0
/tmp/go-build1311866238/b288/ 64/pkg/tool/linux_amd64/vet . -imultiarch
x86_64-linux-gnu(create|run) 64/pkg/tool/linux_amd64/vet .cfg��
pkg/mod/go.opentelemetry.io/prot-errorsas
-plugin-opt=/usr/libexec/gcc/x86-ifaceassert x_amd64/vet
-plugin-opt=-pas/usr/libexec/docker/docker-init
-plugin-opt=-pas--version -plugin-opt=-pass-through=-lpthr-bool
x_amd64/vet` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>File tree
10 files changed
+33
-496
lines changed- internal/cmd
10 files changed
+33
-496
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | | - | |
23 | | - | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 25 | + | |
30 | 26 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 27 | + | |
44 | 28 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 29 | + | |
| 30 | + | |
51 | 31 | | |
52 | 32 | | |
53 | | - | |
54 | | - | |
| 33 | + | |
| 34 | + | |
55 | 35 | | |
56 | 36 | | |
57 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | 16 | | |
22 | 17 | | |
23 | 18 | | |
| |||
32 | 27 | | |
33 | 28 | | |
34 | 29 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
41 | 36 | | |
42 | 37 | | |
43 | 38 | | |
| |||
55 | 50 | | |
56 | 51 | | |
57 | 52 | | |
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 | 53 | | |
93 | 54 | | |
94 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 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 | 150 | | |
191 | 151 | | |
192 | 152 | | |
| |||
270 | 230 | | |
271 | 231 | | |
272 | 232 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | 11 | | |
17 | 12 | | |
18 | 13 | | |
| |||
23 | 18 | | |
24 | 19 | | |
25 | 20 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
30 | 25 | | |
31 | 26 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
0 commit comments