Documentation
¶
Overview ¶
Package commandgen implements `gombit make command`.
It writes a Cobra management command in a feature-package (default internal/commands) as RegisterCommands in commands.go, matching the product template, and registers it from cmd/gombit via go/ast (never regex). Generators are idempotent and additive.
Index ¶
- Constants
- func AddCommandCall(src []byte, constructor string) ([]byte, error)
- func AddImportAndRegister(src []byte, importPath, pkgName string) ([]byte, error)
- func CountConstructorCalls(src []byte, constructor string) (int, error)
- func CountRegisterCalls(src []byte, pkgName string) (int, error)
- func Generate(ctx context.Context, opts Options) error
- type CommandName
- type Options
Constants ¶
const ( // GeneratedBanner marks command files written by this generator. User-owned // files without the banner are refused unless --force is set. GeneratedBanner = "Code generated by gombit make command. DO NOT EDIT." )
Variables ¶
This section is empty.
Functions ¶
func AddCommandCall ¶
AddCommandCall appends `cli.AddCommand(root, <constructor>())` inside `func RegisterCommands` when it is not already present. Idempotent.
func AddImportAndRegister ¶
AddImportAndRegister adds importPath and `<pkg>.RegisterCommands(root)` next to an existing `*.RegisterCommands(root)` call, or immediately after `cli.NewRoot`. Idempotent. `cli.Execute` is not a registration point.
func CountConstructorCalls ¶
CountConstructorCalls reports how many `Constructor()` calls appear in src.
func CountRegisterCalls ¶
CountRegisterCalls reports how many `<pkg>.RegisterCommands(...)` calls appear in src.