generate

package
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 21 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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")
	ErrRepositoryInvalidFormat = errors.NewSentinel("gtb.generate.repository_invalid_format", "repository must contain at least one '/' (e.g. org/repo)")
	ErrHostRequired            = errors.NewSentinel("gtb.generate.host_required", "host 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")
	ErrInvalidOverwriteValue   = errors.NewSentinel("gtb.generate.invalid_overwrite_value", "invalid --overwrite value: must be allow, deny, or ask")
	ErrEnvPrefixInvalid        = errors.NewSentinel("gtb.generate.env_prefix_invalid", "env prefix must contain only uppercase letters, digits, and underscores (e.g. MY_APP)")
	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")
)

Functions

func NewCmdAddFlag

func NewCmdAddFlag(p *props.Props) *cobra.Command

func NewCmdCommand

func NewCmdCommand(p *props.Props, shared *SharedFlags) *cobra.Command

func NewCmdDocs

func NewCmdDocs(p *props.Props, shared *SharedFlags) *cobra.Command

func NewCmdGenerate

func NewCmdGenerate(p *props.Props) *setup.Command

func NewCmdMan added in v0.22.0

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 NewCmdProtect

func NewCmdProtect(p *props.Props) *cobra.Command

func NewCmdSkeleton

func NewCmdSkeleton(p *props.Props, shared *SharedFlags) *cobra.Command

func NewCmdUnprotect

func NewCmdUnprotect(p *props.Props) *cobra.Command

Types

type AddFlagOptions

type AddFlagOptions struct {
	CommandName string
	FlagName    string
	FlagType    string
	Description string
	Persistent  bool
	Shorthand   string
	Path        string
}

func (*AddFlagOptions) Run

func (o *AddFlagOptions) Run(ctx context.Context, p *props.Props) error

func (*AddFlagOptions) ValidateOrPrompt

func (o *AddFlagOptions) ValidateOrPrompt(p *props.Props) error

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
	Agentless            bool
	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) Run

func (o *CommandOptions) Run(ctx context.Context, p *props.Props) error

func (*CommandOptions) ValidateOrPrompt

func (o *CommandOptions) ValidateOrPrompt() error

type DocsOptions

type DocsOptions struct {
	Name            string
	Path            string
	Parent          string
	CommandName     string
	PackagePath     string
	LegacySrc       string
	Agentless       bool
	PublicAPI       bool
	NoAIAttribution bool
	// contains filtered or unexported fields
}

func (*DocsOptions) Run

func (o *DocsOptions) Run(ctx context.Context, p *props.Props) error

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 added in v0.22.0

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".

func (*ManOptions) Run added in v0.22.0

func (o *ManOptions) Run(cmd *cobra.Command, p *props.Props) error

Run renders the man tree (or lists intended files under --dry-run).

type SharedFlags added in v0.39.1

type SharedFlags struct {
	AIProvider string
	AIModel    string
	DryRun     bool
}

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
	GitBackend   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

	// 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

	// 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

	// 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) Run

func (o *SkeletonOptions) Run(ctx context.Context, p *props.Props) error

func (*SkeletonOptions) ValidateOrPrompt

func (o *SkeletonOptions) ValidateOrPrompt(p *props.Props) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL