command

package
v1.25.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ModulesFile = "config/di/modules.go"

Variables

View Source
var MigrationModules = []string{
	"gitlab.com/gorib/waffle/config/service/sql",
	"gitlab.com/gorib/waffle/config/tools/migrate",
}

Functions

func Camel added in v1.10.12

func Camel(name string) string

func Funcs added in v1.10.12

func Funcs() template.FuncMap

Exported so a test renders with the scaffolder's functions, not a copy.

func IsHelp added in v1.9.2

func IsHelp(args []string) bool

func KeptAs added in v1.10.11

func KeptAs(name, where string)

KeptAs reports a declaration left alone because it is already there, naming where it was found — the file it is in is rarely the one that was asked for.

func ModuleEnv added in v1.11.2

func ModuleEnv(name string) []string

func RejectFlags added in v1.9.2

func RejectFlags(args []string) error

Called once a command has taken the flags it knows, so an unrecognised flag fails instead of becoming a positional.

func ReportAction added in v1.10.11

func ReportAction(text string)

func ReportBlock added in v1.10.11

func ReportBlock(text, block string)

For what the scaffolder will not write itself: the lines to paste, and where. Printing beats guessing at a file whose shape is not ours.

func ReportCreated added in v1.10.0

func ReportCreated(paths ...string)

func ReportKept

func ReportKept(paths ...string)

For a caller that decides for itself: a migration carries a timestamp, so the name it would get on this run recognises nothing.

func ReportUnchanged added in v1.14.0

func ReportUnchanged(paths ...string)

For a file that is regenerated rather than scaffolded: "left alone" would claim a choice, and this one was compared and found current.

func TakeBool added in v1.22.0

func TakeBool(args []string, flag string) (bool, []string)

func TakeDriver added in v1.11.0

func TakeDriver(args []string) (string, []string, error)

func TakeValues added in v1.22.0

func TakeValues(args []string, flag, takes string) (values, rest []string, err error)

Called before Operands, which would count a flag and its value as operands.

func Title added in v1.10.12

func Title(name string) string

Folding, not just uppercasing: ValidateName accepts order_item.

func ValidateFileName added in v1.9.2

func ValidateFileName(kind, name string) error

For an operand that becomes one path segment, not a path.

func ValidateName added in v1.9.2

func ValidateName(kind, name string) error

Refused before a file is written: the name reaches the templates as a Go identifier.

func ValidatePath added in v1.9.2

func ValidatePath(kind, p string) error

For an operand that becomes a directory to write into: the generators resolve it against the project root.

func ValidateSubject added in v1.11.0

func ValidateSubject(subject string) error

Deliberately thin: the broker owns the grammar, this only rejects literals that would not survive being written into Keys().

func WriteIfChanged added in v1.22.0

func WriteIfChanged(path string, body []byte) (bool, error)

For a file that is regenerated rather than scaffolded: one already holding body is not touched, so a run that changes nothing leaves no trace on disk.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

func New

func New(name, description string) *Command

func (*Command) Code

func (c *Command) Code() string

func (*Command) Description

func (c *Command) Description() string

func (*Command) Operands added in v1.10.6

func (c *Command) Operands(args []string, min, max int) error

An extra operand used to be dropped in silence: `make:domain:migration orders add index` wrote a migration named "add". Takes RejectFlags with it, so a command cannot close one gap and leave the other.

func (*Command) Usage added in v1.9.1

func (c *Command) Usage() string

func (*Command) WithUsage added in v1.9.1

func (c *Command) WithUsage(operands string) *Command

One string, so a bad invocation and --help cannot disagree.

type CommandName added in v1.10.12

type CommandName struct {
	Raw   string // sweep-otp — the CLI token and the directory
	Snake string // sweep_otp — the DI registration's file name
	Pkg   string // sweepotp — a Go package name carries no separator
	Lower string // sweepOtp — the unexported identifier
	Upper string // SweepOtp — the exported identifier and the import alias
	Words string // sweep otp — the generated description
}

One name, which a CLI token spells differently from a Go package.

func ParseCommandName added in v1.10.12

func ParseCommandName(kind, name string) (CommandName, error)

type Config

type Config struct {
	ApiImport string `yaml:"api_import"`
	ProtoDir  string `yaml:"proto_dir"`
	Mapper    string `yaml:"mapper"`
}

Config mirrors waffle.yaml.

type Project added in v1.22.0

type Project struct {
	// contains filtered or unexported fields
}

Every path a Project takes or reports is relative to the module root, not to the working directory.

func OpenProject added in v1.22.0

func OpenProject() (*Project, error)

func (*Project) ActiveModules added in v1.22.0

func (p *Project) ActiveModules() ([]string, error)

Parsed, not matched: the scaffolded modules.go ships with commented-out blank imports, and a match counts them as active.

func (*Project) Config added in v1.22.0

func (p *Project) Config() (Config, error)

func (*Project) Declares added in v1.22.0

func (p *Project) Declares(dir, name string) (where string, found bool)

Declares reports the file in dir already declaring a type of this name.

Skipping by file path answers a narrower question than the one that matters: model/facility.go declaring Coordinates leaves model/coordinates.go absent and model.Coordinates taken, so writing the second one gives the package two declarations and no build.

func (*Project) EnableMigrations added in v1.22.0

func (p *Project) EnableMigrations() error

EnableMigrations is what a migration runner needs: the runner it writes is a command over a sql.Db, and neither exists until these modules are enabled.

func (*Project) EnableModule added in v1.22.0

func (p *Project) EnableModule(module string) error

func (*Project) EnableStorage added in v1.22.0

func (p *Project) EnableStorage() error

EnableStorage is the tail every command that writes a repository owes: the stored struct carries a go:generate line with no tool behind it and the adapter needs a sql.Db, so a command that writes one and stops here leaves a project that does not build.

func (*Project) EnsureBuiltTool added in v1.22.0

func (p *Project) EnsureBuiltTool(module, owner string) error

EnsureBuiltTool installs module at the version of owner this waffle was built with, so a new service does not get a generator newer than the waffle that scaffolds it.

func (*Project) EnsureTool added in v1.22.0

func (p *Project) EnsureTool(module string) error

EnsureTool adds module via `go get -tool` only if go.mod doesn't already list it — safe (and network-free) to call on every scaffold.

func (*Project) Glob added in v1.22.0

func (p *Project) Glob(pattern string) ([]string, error)

func (*Project) Module added in v1.22.0

func (p *Project) Module() string

func (*Project) Path added in v1.22.0

func (p *Project) Path(elem ...string) string

func (*Project) RequireDomain added in v1.22.0

func (p *Project) RequireDomain(domain string) error

Before the first write: the files a command adds to a domain that is not there are a tree that does not build.

func (*Project) RequireModules added in v1.22.0

func (p *Project) RequireModules(modules ...string) error

Called before the first write with every module the command will enable: reaching a missing line last leaves a half-scaffolded domain behind.

func (*Project) Root added in v1.22.0

func (p *Project) Root() string

func (*Project) Run added in v1.22.0

func (p *Project) Run(name string, args ...string) ([]byte, error)

func (*Project) Write added in v1.22.0

func (p *Project) Write(templates Templates, sources map[string]string, params any) error

type Templates added in v1.22.0

type Templates struct {
	// contains filtered or unexported fields
}

func NewTemplates added in v1.22.0

func NewTemplates(files embed.FS) Templates

func (Templates) Render added in v1.22.0

func (t Templates) Render(source string, params any) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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