Regeneration ♻️¶
Keep your project in sync and your sanity intact with the regenerate commands.
As your tool evolves, the gtb ensures your boilerplate infrastructure keeps up. Whether you've updated your manifest or refactored your code, regeneration is the key to maintaining a healthy project.
1. Regenerate Project¶
The regenerate project command is your primary tool for syncing your code with your manifest.
It reads the .gtb/manifest.yaml file and rebuilds all the cmd.go files, registration logic, and asset bundles.
When to use it?¶
- After editing
manifest.yaml: If you manually updated descriptions, flags, or command structures. - After updating
gtb: To pull in the latest features and bug fixes from the base library. - To fix drift: If you suspect your registration files are out of sync with your intent.
Flags¶
--path,-p: Path to the project root (default: current directory).--force: Danger Zone! Overwrites existingmain.goimplementation files. Use this only if you want to reset a command's logic to the default starter code. On a project still using the legacy flat docs layout,--forcealso migrates the docs to the Diátaxis layout (see below).--dry-run: Preview all changes without writing to disk (see below).
What it does¶
- Rebuilds
cmd.go: Updates Cobra definitions, flags, and descriptions. - Refreshes Assets: Re-bundles any static assets into the binary.
- Injects Imports: Ensures all subcommands are correctly imported and registered in parent commands.
- Manages Lifecycle Files: Creates or removes
init.gobased on thewithInitializervalue in the manifest for each command. IfwithInitializeris enabled but theInit<Name>stub is missing frommain.go, it is appended automatically. - Runs Linting: Automatically executes
golangci-lint run --fixto ensure the generated code is squeaky clean. - Conflict Detection: Checks if
cmd.gofiles have been manually modified and prompts for confirmation before overwriting (unless--forceis used).
Migrating docs to the Diátaxis layout¶
If the project still uses the legacy flat docs layout (docs/commands/, docs/packages/), regenerate project --force migrates it to the Diátaxis quadrant layout:
- Moves existing command pages into
docs/reference/cli/and package pages intodocs/explanation/components/, preserving your hand-written content (pages are moved, not regenerated). - Stamps
docs_layout: diataxison.gtb/manifest.yamlso future generation targets the new tree. - Removes the old
docs/commands/anddocs/packages/trees.
Commit first
The migration deletes the old trees once content has moved. Commit (or stash) your work before running it so the move is easy to review and revert.
Dry-Run Mode¶
Use --dry-run to preview what regenerate project would do without modifying any files:
This produces a summary of:
- Files to create: New files that would be generated.
- Files to modify: Existing files that would change, shown as unified diffs.
Under the hood, the dry-run materialises all generated files into a temporary directory, runs the same post-processing steps as a real regeneration (go mod tidy, golangci-lint run --fix), and diffs the result against your current project. This ensures the preview is accurate — including formatting and import tidying.
Tip
Dry-run is particularly useful after editing manifest.yaml to verify that a regenerate project will produce the changes you expect before committing to them.
2. Regenerate Manifest¶
The regenerate manifest command works in the opposite direction. It scans your existing Go source code and rebuilds the manifest.yaml.
When to use it?¶
- After manual refactoring: If you moved command files around manually and want the manifest to reflect the new structure.
- Recovering a lost manifest: If your
manifest.yamlwas deleted or corrupted, this can reconstruct it from your code.
Flags¶
--path,-p: Path to the project root (default: current directory).
How it works¶
It parses your project's AST to find cobra.Command definitions and reconstructs the manifest — command names/descriptions/aliases/args, flag definitions, parent/child relationships, per-command options (withAssets, preRun hooks, withInitializer), and project-level properties. For the full extraction rules, see the regenerate command explanation.
Source of Truth
While regenerate manifest is a powerful recovery tool, we recommend treating the Manifest as your source of truth and driving changes through it (or generate commands) rather than the other way around.