commandgen

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 16 Imported by: 0

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

View Source
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

func AddCommandCall(src []byte, constructor string) ([]byte, error)

AddCommandCall appends `cli.AddCommand(root, <constructor>())` inside `func RegisterCommands` when it is not already present. Idempotent.

func AddImportAndRegister

func AddImportAndRegister(src []byte, importPath, pkgName string) ([]byte, error)

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

func CountConstructorCalls(src []byte, constructor string) (int, error)

CountConstructorCalls reports how many `Constructor()` calls appear in src.

func CountRegisterCalls

func CountRegisterCalls(src []byte, pkgName string) (int, error)

CountRegisterCalls reports how many `<pkg>.RegisterCommands(...)` calls appear in src.

func Generate

func Generate(ctx context.Context, opts Options) error

Generate writes a management command into an existing Gombit app.

Types

type CommandName

type CommandName struct {
	Input       string
	Use         string
	Constructor string
	FileBase    string
	Package     string
}

CommandName is the derived identifiers for one generated management command.

type Options

type Options struct {
	WorkDir string
	Name    string
	Package string
	DryRun  bool
	Force   bool
	Stdout  io.Writer
	Stderr  io.Writer
}

Options configures management-command generation inside an existing app.

Jump to

Keyboard shortcuts

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