Documentation
¶
Index ¶
- Constants
- Variables
- func Camel(name string) string
- func Funcs() template.FuncMap
- func IsHelp(args []string) bool
- func KeptAs(name, where string)
- func ModuleEnv(name string) []string
- func RejectFlags(args []string) error
- func ReportAction(text string)
- func ReportBlock(text, block string)
- func ReportCreated(paths ...string)
- func ReportKept(paths ...string)
- func ReportMissing(paths ...string)
- func ReportUnchanged(paths ...string)
- func ReportWarning(text string)
- func TakeBool(args []string, flag string) (bool, []string)
- func TakeDriver(args []string) (string, []string, error)
- func TakeValues(args []string, flag, takes string) (values, rest []string, err error)
- func Title(name string) string
- func ValidateFileName(kind, name string) error
- func ValidateName(kind, name string) error
- func ValidatePath(kind, p string) error
- func ValidateSubject(subject string) error
- func WriteIfChanged(path string, body []byte) (bool, error)
- type Command
- type CommandName
- type Config
- type Project
- func (p *Project) ActiveModules() ([]string, error)
- func (p *Project) Config() (Config, error)
- func (p *Project) Declares(dir, name string) (where string, found bool)
- func (p *Project) EnableMigrations() error
- func (p *Project) EnableModule(module string) error
- func (p *Project) EnableStorage() error
- func (p *Project) EnsureBuiltTool(module, owner string) error
- func (p *Project) EnsureTool(module string) error
- func (p *Project) Glob(pattern string) ([]string, error)
- func (p *Project) Module() string
- func (p *Project) Path(elem ...string) string
- func (p *Project) RequireDomain(domain string) error
- func (p *Project) RequireModules(modules ...string) error
- func (p *Project) Root() string
- func (p *Project) Run(name string, args ...string) ([]byte, error)
- func (p *Project) Write(templates Templates, sources map[string]string, params any) error
- type Templates
Constants ¶
const ModulesFile = "config/di/modules.go"
Variables ¶
var MigrationModules = []string{
"gitlab.com/gorib/waffle/config/service/sql",
"gitlab.com/gorib/waffle/config/tools/migrate",
}
Functions ¶
func Funcs ¶ added in v1.10.12
Exported so a test renders with the scaffolder's functions, not a copy.
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 RejectFlags ¶ added in v1.9.2
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 ReportMissing ¶ added in v1.10.6
func ReportMissing(paths ...string)
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 ReportWarning ¶ added in v1.10.1
func ReportWarning(text string)
Not an error: the run succeeded, and this is about something it deliberately did not touch.
func TakeValues ¶ added in v1.22.0
Called before Operands, which would count a flag and its value as operands.
func ValidateFileName ¶ added in v1.9.2
For an operand that becomes one path segment, not a path.
func ValidateName ¶ added in v1.9.2
Refused before a file is written: the name reaches the templates as a Go identifier.
func ValidatePath ¶ added in v1.9.2
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
Deliberately thin: the broker owns the grammar, this only rejects literals that would not survive being written into Keys().
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func (*Command) Description ¶
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 (*Project) ActiveModules ¶ added in v1.22.0
Parsed, not matched: the scaffolded modules.go ships with commented-out blank imports, and a match counts them as active.
func (*Project) Declares ¶ added in v1.22.0
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
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 (*Project) EnableStorage ¶ added in v1.22.0
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
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
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) RequireDomain ¶ added in v1.22.0
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
Called before the first write with every module the command will enable: reaching a missing line last leaves a half-scaffolded domain behind.