cmd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package cmd contains the implementation of each Artisan subcommand. Each command is a constructor returning a *cobra.Command — easy to compose, easy to unit-test, and decoupled from the App in cli/cli.go via the Env struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDBSeed

func NewDBSeed(env *Env) *cobra.Command

NewDBSeed returns `db:seed [SeederName...]`. With no args, all registered seeders run in dependency order. Named seeders restrict the run to that subset (their dependencies still run first).

func NewDBWipe

func NewDBWipe(env *Env) *cobra.Command

NewDBWipe returns `db:wipe` — DROPs every user table. Refuses to run without --force. Useful for tests; not intended for production.

func NewInit added in v0.2.0

func NewInit(_ *Env) *cobra.Command

NewInit returns `artisan init` — writes a starter `lago.json` to the current directory. Refuses to overwrite without --force.

func NewMakeCRUD added in v0.2.0

func NewMakeCRUD(env *Env) *cobra.Command

NewMakeCRUD returns `make:crud <Name> --fields=...` — a one-shot scaffold that generates the model, migration, factory, seeder, and test from a single field spec. This is the "Laravel-equivalent" of running `php artisan make:model -mfsr` plus a controller scaffold.

artisan make:crud Post \
    --fields="title:string,body:text,published:bool:default(false)"

The same field declarations end up in every artifact, so column names and types stay in lockstep across the model + migration + factory.

func NewMakeFactory

func NewMakeFactory(env *Env) *cobra.Command

NewMakeFactory returns the `make:factory` command.

artisan make:factory UserFactory --model=User
artisan make:factory UserFactory --model=User \
    --fields="name:string,email:string"

Field types determine which faker method is invoked in the generated factory; well-known column names (name, email, phone, …) get the most natural call automatically.

func NewMakeMigration

func NewMakeMigration(env *Env) *cobra.Command

NewMakeMigration returns the `make:migration` command.

artisan make:migration create_users_table
artisan make:migration create_users_table --fields="name:string,email:string:unique"
artisan make:migration add_email_to_users --table=users

func NewMakeModel

func NewMakeModel(env *Env) *cobra.Command

NewMakeModel returns the `make:model` command. Flags:

-m         also create a migration for the model
-f         also create a factory
-s         also create a seeder
-t         also create a test
-a         all of the above
--fields   field spec: name:type[:modifier], comma-separated
--dir      output directory (default: models/)
--force    overwrite existing files

Example:

artisan make:model Post -m -f \
    --fields="title:string,body:text,published:bool:default(false)"

Fields declared once on the command line are written identically to the model (PascalCase + column tag) and to the migration (snake_case schema methods) so the two stay in lockstep.

func NewMakeSeeder

func NewMakeSeeder(env *Env) *cobra.Command

NewMakeSeeder returns the `make:seeder` command.

func NewMakeTest

func NewMakeTest(env *Env) *cobra.Command

NewMakeTest returns the `make:test` command.

artisan make:test User       → tests/user_test.go (TestUser)
artisan make:test PaymentFlow → tests/payment_flow_test.go (TestPaymentFlow)

func NewMigrateFresh

func NewMigrateFresh(env *Env) *cobra.Command

NewMigrateFresh returns the `migrate:fresh` command (drop all tables + up).

func NewMigrateRefresh

func NewMigrateRefresh(env *Env) *cobra.Command

NewMigrateRefresh returns the `migrate:refresh` command (rollback + up).

func NewMigrateReset

func NewMigrateReset(env *Env) *cobra.Command

NewMigrateReset returns the `migrate:reset` command.

func NewMigrateRollback

func NewMigrateRollback(env *Env) *cobra.Command

NewMigrateRollback returns the `migrate:rollback` command.

func NewMigrateStatus

func NewMigrateStatus(env *Env) *cobra.Command

NewMigrateStatus returns the `migrate:status` command.

func NewMigrateStep

func NewMigrateStep(env *Env) *cobra.Command

NewMigrateStep returns the `migrate:step` command.

func NewMigrateUp

func NewMigrateUp(env *Env) *cobra.Command

NewMigrateUp returns the `migrate` command.

func SetStubFS

func SetStubFS(filesystem fs.FS)

SetStubFS lets the cli package (or applications) install the embedded stub filesystem. It is called automatically by cli.New(); applications that embed their own stub directory can replace it.

We avoid making this package responsible for the //go:embed directive because relative embed paths cannot escape upward, and we want stubs to live at cli/stubs/ rather than cli/cmd/stubs/ (the latter would shadow the implementation package).

func SetStubOverride

func SetStubOverride(stub, path string)

SetStubOverride redirects a specific stub to a file path on disk. Useful for projects that ship branded code generators.

Types

type Env

type Env struct {
	// Connection lazily returns the active *database.Connection.
	Connection func(ctx context.Context) (*database.Connection, error)
	Migrations *migrations.Registry
	Seeders    *seeder.Registry
	Logger     *logger.Logger
	// Timeout is the upper bound applied to commands that touch the DB.
	Timeout time.Duration
}

Env is the shared environment commands resolve at runtime. It is constructed by cli.App and passed to each cmd.New* constructor.

type FieldSpec added in v0.2.0

type FieldSpec struct {
	// Column is the SQL column name (snake_case). This is the canonical
	// name — the model field name is computed from it (PascalCase).
	Column string
	// Type is the portable type name (string, text, int, bigint, bool,
	// float, decimal, json, uuid, date, datetime, time).
	Type string
	// Modifiers carries flags like "unique", "nullable", "index".
	Modifiers []string
	// Default is the default value literal (raw — emitted as-is into the
	// migration); empty means no default.
	Default string
}

FieldSpec describes one field of a model. It is parsed from the CLI's --fields flag — e.g. `--fields=name:string,email:string:unique,age:int`.

func ParseFields added in v0.2.0

func ParseFields(spec string) ([]FieldSpec, error)

ParseFields parses a `--fields=name:string,email:string:unique` spec into a slice of FieldSpec. Whitespace around tokens is tolerated.

Default values use `default(X)` syntax — `is_admin:bool:default(false)` — to avoid colliding with the modifier separator.

func (FieldSpec) FakerCall added in v0.2.0

func (f FieldSpec) FakerCall() string

FakerCall picks an appropriate faker method for this field, based on type + a few well-known column names. Returns "" when no convenient faker exists, in which case the generator emits a TODO comment.

func (FieldSpec) FieldName added in v0.2.0

func (f FieldSpec) FieldName() string

FieldName returns the Go struct field name (PascalCase), e.g. "user_id" → "UserID" — preserving common acronyms via the inflect package.

func (FieldSpec) GoType added in v0.2.0

func (f FieldSpec) GoType() string

GoType returns the Go type the field is mapped to.

func (FieldSpec) MigrationCall added in v0.2.0

func (f FieldSpec) MigrationCall() string

MigrationCall returns the schema.Blueprint method call for this field — e.g. `t.String("email").Unique()` — used by the migration stub.

func (FieldSpec) NeedsTimeImport added in v0.2.0

func (f FieldSpec) NeedsTimeImport() bool

NeedsTimeImport reports whether the field uses a time.* Go type.

type Paths added in v0.2.0

type Paths struct {
	Models     string `json:"models"`
	Migrations string `json:"migrations"`
	Factories  string `json:"factories"`
	Seeders    string `json:"seeders"`
	Tests      string `json:"tests"`
}

Paths declares the directories the make:* commands write to.

func DefaultPaths added in v0.2.0

func DefaultPaths() Paths

DefaultPaths returns the conventional layout (Laravel-flavored).

type ProjectConfig added in v0.2.0

type ProjectConfig struct {
	Paths Paths `json:"paths"`
}

ProjectConfig is the per-project configuration loaded from `lago.json` (or the path in LAGO_CONFIG). It lets each project decide where models, migrations, factories, seeders, and tests live — so one team can keep everything under `internal/`, another at the repo root, and a third in `database/`, all with the same artisan binary.

func LoadProject added in v0.2.0

func LoadProject() *ProjectConfig

LoadProject returns the project config, loading and caching it on first call. The cache is process-scoped so commands within one binary share it.

Resolution order:

  1. The path in $LAGO_CONFIG, if set
  2. `lago.json` in the current directory
  3. Built-in defaults (see DefaultPaths)

Jump to

Keyboard shortcuts

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