Skip to content

Commit 9eb70db

Browse files
committed
docs: document cmd layout conventions
1 parent 8d1aecc commit 9eb70db

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# AGENTS
2+
3+
## Cobra Command Layout
4+
5+
- Keep `cmd` flat: one top-level command belongs in one top-level Go file under `cmd/`.
6+
- Do not create per-command subdirectories under `cmd` for normal CLI commands. The intended shape is:
7+
- `cmd/pg.go` for `pig pg` / `pig postgres`
8+
- `cmd/pb.go` for `pig pb` / `pig pgbackrest`
9+
- `cmd/pt.go` for `pig pt` / `pig patroni`
10+
- `cmd/pe.go` for `pig pe` / `pig pg_exporter`
11+
- `cmd/sty.go`, `cmd/do.go`, `cmd/repo.go`, etc. for their matching top-level commands
12+
- A command may have a matching top-level test file, for example `cmd/pg_test.go` for `cmd/pg.go`.
13+
- Complex commands such as `pg`, `pb`, and `pt` should still stay in one command file unless the user explicitly asks for a different layout.
14+
- `cmd/root.go` owns root command setup, global flags, and top-level command registration.
15+
- `cmd/utils.go` owns shared command-layer helpers used by multiple command files.
16+
- Keep `cmd` files as clean Cobra entry points: define command names, aliases, annotations, flags, argument validation, and option mapping there.
17+
- Put concrete business logic in the relevant `cli/*`, `internal/*`, or other implementation package instead of growing it inside `cmd`.
18+
- Avoid duplicated command glue. Reuse shared helpers such as annotation builders, structured output handling, plan rendering, log-output validation, and legacy structured wrappers.

0 commit comments

Comments
 (0)