Documentation
¶
Overview ¶
Package generate provides Cobra commands for scaffolding new CLI projects (project/skeleton), adding commands to existing projects, converting implementations to AI-generated code, and adding flags to commands — all driven by manifest definitions and interactive wizards.
Index ¶
- Variables
- func NewCmdAddFlag(p *props.Props) *cobra.Command
- func NewCmdCommand(p *props.Props, shared *SharedFlags) *cobra.Command
- func NewCmdDocs(p *props.Props, shared *SharedFlags) *cobra.Command
- func NewCmdGenerate(p *props.Props) *setup.Command
- func NewCmdMan(p *props.Props, shared *SharedFlags) *cobra.Command
- func NewCmdProtect(p *props.Props) *cobra.Command
- func NewCmdSkeleton(p *props.Props, shared *SharedFlags) *cobra.Command
- func NewCmdUnprotect(p *props.Props) *cobra.Command
- func NewCmdWizard(p *props.Props) *setup.Command
- type AddFlagOptions
- type CommandOptions
- type DocsOptions
- type FlagFormInput
- type ManOptions
- type SharedFlags
- type SkeletonOptions
- type WizardOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrCommandNameRequired = errors.NewSentinel("gtb.generate.command_name_required", "command name is required") ErrFlagNameRequired = errors.NewSentinel("gtb.generate.flag_name_required", "flag name is required") ErrNameRequired = errors.NewSentinel("gtb.generate.name_required", "name is required") ErrRepositoryRequired = errors.NewSentinel("gtb.generate.repository_required", "repository is required") ErrEmptyCommandPath = errors.NewSentinel("gtb.generate.empty_command_path", "empty command path") ErrCommandNotFound = errors.NewSentinel("gtb.generate.command_not_found", "command not found in manifest") ErrUpdateManifestFailed = errors.NewSentinel("gtb.generate.update_manifest_failed", "failed to update manifest") ErrNonInteractive = errors.NewSentinel("gtb.generate.non_interactive", "non-interactive mode detected, missing required flags: run from a terminal, pass the answers as flags, or add --accessible (GTB_ACCESSIBLE=true) for line prompts on a piped stdin") ErrInvalidOverwriteValue = errors.NewSentinel("gtb.generate.invalid_overwrite_value", "invalid --overwrite value: must be allow, deny, or ask") ErrInvalidSigningKeySource = errors.NewSentinel("gtb.generate.invalid_signing_key_source", "invalid --signing-key-source: must be embedded, external, or both") ErrInvalidSigningBackend = errors.NewSentinel("gtb.generate.invalid_signing_backend", "invalid --signing-backend: not a registered signing backend") ErrGitFlagsConflict = errors.NewSentinel("gtb.generate.git_flags_conflict", "conflicting flags: --no-git skips the initial commit that --push would publish") ErrModuleRequired = errors.NewSentinel("gtb.generate.module_required", "a project that is not hosted on a forge needs --module") ErrReleaseChannelRequired = errors.NewSentinel("gtb.generate.release_channel_required", "self-update needs a release channel: the project's forge (--release-channel forge, hosted projects only) or a static location (--release-channel static --release-base-url <https URL>), or drop update from --features") ErrReleaseBaseURLRequired = errors.NewSentinel("gtb.generate.release_base_url_required", "the static release channel needs the location its releases are published under: --release-base-url <https URL>") ErrReleaseBaseURLNotStatic = errors.NewSentinel("gtb.generate.release_base_url_not_static", "--release-base-url is read only with --release-channel static") ErrHelpChannelRequired = errors.NewSentinel("gtb.generate.help_channel_required", "a help channel type needs its channel: --slack-channel for slack, --teams-channel for teams") ErrSigningKeyWithoutSigning = errors.NewSentinel("gtb.generate.signing_key_without_signing", "--signing-key-id wires the release pipeline's signs block, which needs --signing (or --signing-email)") )
var ErrConfigSourceFlag = errors.NewSentinel("gtb.generate.config_source_flag", "invalid config source flag")
ErrConfigSourceFlag is a --config-source value that is not name=kind, or a slot list naming a slot no --config-source declares.
Functions ¶
func NewCmdCommand ¶
func NewCmdCommand(p *props.Props, shared *SharedFlags) *cobra.Command
func NewCmdDocs ¶
func NewCmdDocs(p *props.Props, shared *SharedFlags) *cobra.Command
func NewCmdMan ¶
func NewCmdMan(p *props.Props, shared *SharedFlags) *cobra.Command
NewCmdMan returns the "gtb generate man" subcommand. It renders roff man pages for the running binary's own command tree into <dir>/man<section>/, the artefact path Linux packagers and CI consume. It documents gtb's own tree; a scaffolded downstream tool runs its own "man" command instead.
func NewCmdSkeleton ¶
func NewCmdSkeleton(p *props.Props, shared *SharedFlags) *cobra.Command
Types ¶
type AddFlagOptions ¶
type AddFlagOptions struct {
CommandName string
FlagName string
FlagType string
Description string
Persistent bool
Shorthand string
Path string
}
func (*AddFlagOptions) ValidateOrPrompt ¶
type CommandOptions ¶
type CommandOptions struct {
Name string
Short string
Long string
Path string
WithAssets bool
Parent string
Args string
Flags []string
AliasesInput string // For form input
Aliases []string
ScriptPath string
Prompt string
MaxSteps int
NonInteractive bool
PersistentPreRun bool
PreRun bool
Force bool
WithInitializer bool
WithConfigValidation bool
Protected *bool
MCPEnabled *bool // tri-state MCP exposure; nil = default (exposed)
ExposeToMCP bool // interactive-form value; true = exposed (default)
Options []string // For MultiSelect
AddFlags bool // Whether to show the flag entry stage
AddPrompt bool // Whether to show the AI prompt stage
// contains filtered or unexported fields
}
func (*CommandOptions) ValidateOrPrompt ¶
type DocsOptions ¶
type FlagFormInput ¶
type FlagFormInput struct {
Name string
Type string
Description string
Persistent bool
Shorthand string
Required bool
Default string
DefaultIsCode bool
AddAnother bool
}
FlagFormInput holds data for a single flag collected via the interactive form.
type ManOptions ¶
type ManOptions struct {
Dir string
Section string
Source string
Manual string
Date string
// contains filtered or unexported fields
}
ManOptions holds the flags for "gtb generate man".
type SharedFlags ¶
type SharedFlags struct {
}
SharedFlags carries the values of `generate`'s persistent flags to the subcommands that read them.
These were package-level variables, which pflag wrote to directly. That made building two command trees a data race — harmless in the binary, which builds one in main, but it meant no test could construct the tree in parallel, and it is the pattern AGENTS.md forbids for exactly this reason. One allocation per NewCmdGenerate has neither problem.
type SkeletonOptions ¶
type SkeletonOptions struct {
Name string
ForgeBackend string
Repo string
Host string
Private bool
Description string
Path string
GoVersion string
Features []string
HelpType string
Overwrite string
SlackChannel string
SlackTeam string
TeamsChannel string
TeamsTeam string
EnvPrefix string
// UpdatePolicy is the generated tool's self-update posture baseline
// (disabled / prompt / enabled). Empty leaves it unset so the framework
// default (disabled) applies.
UpdatePolicy string
// MCPMode is the MCP publication mode (spec 0201 D3).
MCPMode string
// MCPExposed are the command paths ticked on the revisit wizard's surface
// page; mcpCommands is what the page offers, loaded from the manifest
// (spec 0202 D9).
MCPExposed []string
// UpdateCheckInterval is the generated tool's baseline self-update-check
// throttle as a Go duration string (e.g. "24h"). Empty leaves it unset so
// the framework default (24h) applies.
UpdateCheckInterval string
// NoForge marks a project that is not hosted on a forge (spec 0195 D3):
// no backend, no repository, and Module names the Go module path.
NoForge bool
// Module is the Go module path; required with NoForge, an override of
// <host>/<org>/<repo> otherwise (spec 0195 D5, OQ6).
Module string
// ForgeCredentials are further forges enabled for their credential
// wizard and adapter only (spec 0195 D6).
ForgeCredentials []string
// ReleaseChannel is forge or static when update is enabled (spec 0195
// D7, spec 0203 D1); empty resolves to forge for a hosted project.
ReleaseChannel string
// ReleaseBaseURL is the static channel's location (spec 0203 D1).
ReleaseBaseURL string
// CIComponentSource overrides the phpboyscout/cicd include base in the
// scaffolded GitLab pipeline (GitLab backend only). Empty uses the
// framework default, gitlab.com/phpboyscout/cicd.
CIComponentSource string
// Git post-generation step. NoGit opts out of the default init + initial
// commit; Push (opt-in) additionally adds the derived remote and pushes;
// GitBranch overrides the default branch the initial commit lands on.
NoGit bool
Push bool
GitBranch string
// Signing (off by default). When Signing is true the generated tool
// scaffolds internal/trustkeys and wires props.Signing. require_signature
// is intentionally not collectable here — it stays false until a signed
// release has shipped and is only ever flipped via `gtb enable signing`.
Signing bool
SigningEmail string
SigningKeySource string
SigningRequireExternalCrosscheck bool
// Release-pipeline fields. Recording a key id wires the generated
// GoReleaser signs block; backend/region/public-key default in the
// generator when a key id is set.
SigningBackend string
SigningKeyID string
SigningKMSRegion string
SigningPublicKey string
// ChatProviders is what cmd/<name>/chat.go links, as chat.Provider names:
// a shortcut for wiring go/chat modules, recorded whether or not the ai
// feature is on (#94). Nothing by default; ai with no explicit list takes
// every provider the framework can configure, and an explicit empty list
// with ai is refused (spec 0194 D5, D7, OQ4, OQ5).
ChatProviders []string
// ChatProvidersSet records that the list was given, so ai can tell an
// omitted list (take the defaults) from an empty one (refused).
ChatProvidersSet bool
// TelemetryEndpoint and TelemetryOTelEndpoint are where the telemetry
// feature sends; recorded under properties.telemetry (spec 0197 D4).
TelemetryEndpoint string
TelemetryOTelEndpoint string
// Bootstrap is the config-bootstrap posture (auto-initialise, the commands
// that skip the config check, the auxiliary fast-path commands).
Bootstrap generator.ManifestBootstrap
// ConfigLayers declares which config-stack layers the tool wires; empty
// inherits the framework default.
ConfigLayers []string
// ConfigFormats are the config formats the tool links beyond YAML, and
// ConfigFormat its own (spec 0204 D2).
ConfigFormats []string
ConfigFormat string
// ConfigKeyCase is the config stack's key mode, folded or exact (spec 0209).
ConfigKeyCase string
// ConfigSources are the declared source slots as name=kind, and the two
// lists name the optional and the writable ones (spec 0204 D15).
ConfigSources []string
ConfigSourcesOptional []string
ConfigSourcesWritable []string
// SigningRequireSignature and SigningRequireChecksum are the enforcement
// baselines. Only the checksum one is asked on a first run; the signature
// one is a footgun before a signed release has shipped (0071), so the
// wizard asks it only on a revisit (spec 0197 D5).
SigningRequireSignature bool
SigningRequireChecksum bool
// NoVerify skips go mod tidy and golangci-lint after generation; the run
// then exits 0 having emitted files it did not verify (spec 0197 D10).
NoVerify bool
// ChatDefault is the author's default provider, model and addressing,
// recorded in the manifest and shipped as the tool's lowest config layer.
// Required when several providers are linked (spec 0196 D1, D9).
ChatDefault generator.ManifestChatDefault
// ChatToolBridge false opts out of linking the tool bridge a local-CLI
// provider needs; nil keeps the default rule (#104).
ChatToolBridge *bool
// GeneratorAI is the project's recorded choice on gtb calling a model
// while generating it; nil defers to the person's generator.ai (spec 0211).
GeneratorAI *bool
// Templates carries the custom template-overlay specs (<src>@<ref>)
// supplied via --template (repeatable). Each is parsed into a manifest
// TemplateSource and layered over the embedded skeleton.
Templates []string
// contains filtered or unexported fields
}
func (*SkeletonOptions) ValidateOrPrompt ¶
type WizardOptions ¶ added in v0.43.0
WizardOptions drives `gtb wizard`: the generation wizard over an existing project's manifest (spec 0197 D13).