commandgen

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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