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/mapon/go.mod to depend on cli submodule
- document embedding pattern in AGENTS.md
Copy file name to clipboardExpand all lines: AGENTS.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,40 @@ This separation lets consumers embed the CLI in a larger tool or swap the storag
32
32
33
33
The Mapon API uses a single API key for all requests. The key is stored in the credential store.
34
34
35
+
### Embedding in a Parent CLI
36
+
37
+
The CLI can be embedded as a subcommand in a larger tool (e.g. a unified `way` CLI). Key design rules:
38
+
39
+
-**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).
40
+
-**`WithHTTPClient`** — the parent injects an `*http.Client` via `cli.WithHTTPClient()`. The SDK layers (auth, retry) stack on top of the injected client's transport.
41
+
-**`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