You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(cli): add WithHTTPClient injection, separate cli module
- export DebugTransport with lazy Enabled *bool for embedding
- add WithHTTPClient option, remove WithDebug from client
- move --debug flag from cli package to standalone main.go
- create separate cli/go.mod to prevent cobra leaking into SDK
- update cmd/mbz/go.mod to depend on cli submodule
- document embedding pattern in AGENTS.md
Copy file name to clipboardExpand all lines: AGENTS.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,41 @@ The Mercedes-Benz API uses two auth methods depending on the endpoint:
45
45
46
46
Both are stored in the credential store. The OAuth2 token is cached separately in the token store.
47
47
48
+
### Embedding in a Parent CLI
49
+
50
+
The CLI can be embedded as a subcommand in a larger tool (e.g. a unified `way` CLI). Key design rules:
51
+
52
+
-**Never use `cmd.Root()`** — resolves to the parent CLI's root when embedded, breaking flag lookups. Use `cmd.Flags()` instead (works for both persistent and local flags).
53
+
-**`WithHTTPClient`** — the parent injects an `*http.Client` via `cli.WithHTTPClient()`. The SDK layers (auth, retry) stack on top of the injected client's transport.
54
+
-**`DebugTransport`** — exported in `debug.go` with a lazy `Enabled *bool` field. The parent owns the `--debug` flag and points `Enabled` at the flag variable. The transport checks the pointer at request time, solving the chicken-and-egg problem (transport constructed before flag parsing).
0 commit comments