Skip to Content
agore-skill
How-to Guides

How to add a CLI command

Wire a new cobra command into the App-injected command tree without breaking the six-command contract.

You want to extend the command surface. Careful: the CLI is specified to have exactly six project commands (init, create, inspect, lint, eval, release), and that surface is documented as part of the product contract (--help additionally lists the fang-provided completion and help helpers, which are not part of it). A new command is a product decision first — this page is the mechanical path once it is agreed.

Understand the structure

internal/cli/root.go defines the command tree and the App struct. Every effectful operation — git lookups, PATH searches, TTY prompting, the GitHub publish — is a field on App; NewApp() wires the real environment, and tests inject fakes. A command file (init.go, create.go, …) defines one cobra command and closes over the App.

Add the command

  1. Create internal/cli/<name>.go with a builder function taking *App and returning a *cobra.Command, following the existing files.
  2. Register it in NewRootCmdWithApp in root.go.
  3. Use the App helpers (app.workdir(), app.configPath(cmd), app.lookPath, …) for anything effectful — never reach for os.Getenv or exec.Command directly.
  4. Errors: return them; the entry point maps any returned error to exit code 1 with an ERROR banner via charmbracelet/fang.
  5. Zero-config: commands other than release must keep working without an agore.yaml.

Test the command

internal/cli/cli_test.go builds an App with fakes (captured writers, fake RunCommand, fake git helpers, no TTY) and drives commands end to end. Add:

  • a happy-path case,
  • each error case with its exact message,
  • the exit path (assert on the returned error).
mise run test

Keep the docs and the landing honest

  • Add the command to CLI overview and give it its own reference page (docs/content/docs/en/user/reference/, and the zh mirror).
  • The landing page's "Six commands, one lifecycle" bento and command overview live in docs/app/[lang]/(home)/page.tsx.
  • The CLI's Long description in root.go is the banner text quoted in the docs.

Pass the gate

mise run check

On this page