Entry & Dispatch
The shebang'd executable that package.json#bin points at. Parses argv, picks a command handler, and exits with the handler's return code.
Purpose
The shebang'd executable that package.json#bin points at. Parses argv, picks a command handler, and exits with the handler's return code.
Shape
#!/usr/bin/env bun
import { run } from "../cli/index.ts"
run(Bun.argv.slice(2)).then(
(code) => process.exit(code ?? 0),
(err) => { /* see 07-logging-errors.md */ process.exit(1) }
)
Dispatch table
| Argument | Handler |
|---|---|
dev | cli/commands/dev.ts |
build | cli/commands/build.ts |
deploy | cli/commands/deploy.ts |
secret | cli/commands/secret.ts |
--version, -v | print version from package.json, exit 0 |
--help, -h, help, no args | print usage, exit 0 |
| unknown | print usage + the unknown token, exit 2 |
Flag parsing
- Use a tiny hand-rolled parser. No
commander, noyargs. - Global flags:
--cwd <path>(defaultprocess.cwd()),--config <path>(overrides discovery),--verbose. - Command-specific flags live in each command's spec.
Cwd handling
Resolve --cwd to an absolute path early. All later file lookups (config, app dir, output) treat that path as the root. Never read from process.cwd() after this point.
Acceptance criteria
pattieswith no args prints usage and exits 0.patties --versionprints the version on stdout.patties frobnicateexits 2 with "unknown command: frobnicate" plus usage.patties dev --cwd /tmp/appoperates on/tmp/app, ignoringprocess.cwd().