zz_rotini.go
go generate ./... turns your spec into one Go file, internal/cmd/<name>/zz_rotini.go. It is
rewritten on every run, so you never edit it — and you rarely need to read it. This page
explains what is in it, so the step from spec to code is not a mystery.
From spec to code
For a spec with a todo command and an add sub-command, the file holds:
| In the spec | In zz_rotini.go |
|---|---|
| each command’s flags | a struct — TodoAddFlags { Priority string; Tag []string } |
| each command’s arguments | a struct — TodoAddArguments { Title string } |
| its env and config inputs, when it declares any | TodoAddEnv and TodoAddConfig structs |
| the command and its parents | TodoAddInputs, the type your handler passes to rotini.Collect |
| the command tree | a rotini.Definition the runtime parses against |
| each command | a method wiring it to your handler type (todoAddHandlers) |
| configuration files and env prefix | BindMeta, which tells the runtime where values come from |
| the help feature | Help(path...), the rendered help pages |
It ends with the one thing you do use: Program, built by NewProgram, which main.go runs.
zz_rotini.go (abridged)
// Code generated by rotini; DO NOT EDIT.
package todo
type TodoAddFlags struct {
Priority string `rotini:"priority"`
Tag []string `rotini:"tag"`
}
type TodoAddArguments struct {
Title string `rotini:"title"`
}
type TodoAddInputs struct {
Todo TodoCommandInputs
TodoAdd TodoAddCommandInputs
}
func NewProgram(handlers ProgramHandlers) *rotini.Program {
return rotini.NewProgram(definition, handlers).
WithBindMeta(BindMeta).
WithHelp(Help)
}
var Program = NewProgram(&handlers{})What stays yours
- The handler files — one per command, created the first time a command appears and never
overwritten. If you remove a command from the spec, its handler file is removed on the next
go generate(generateprints what it removed), edits and all; delete the file’svar _ rotini.Handlersline or list it under the conf’skeep:to hold on to it. main.go— created once, never touched again.
Names
Generated names follow Go’s conventions: api-group becomes APIGroup, base-url becomes
BaseURL. A command port-forward gets the handler file todo_port_forward.go.