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 ¶
- func NewDB(env *Env) *cobra.Command
- func NewDBSeed(env *Env) *cobra.Command
- func NewDBShow(env *Env) *cobra.Command
- func NewDBTable(env *Env) *cobra.Command
- func NewDBWipe(env *Env) *cobra.Command
- func NewEnv(_ *Env) *cobra.Command
- func NewEnvInit(_ *Env) *cobra.Command
- func NewInit(_ *Env) *cobra.Command
- func NewKeyGenerate(_ *Env) *cobra.Command
- func NewMakeCRUD(env *Env) *cobra.Command
- func NewMakeController(env *Env) *cobra.Command
- func NewMakeFactory(env *Env) *cobra.Command
- func NewMakeMigration(env *Env) *cobra.Command
- func NewMakeModel(env *Env) *cobra.Command
- func NewMakeScheme(_ *Env) *cobra.Command
- func NewMakeSeeder(env *Env) *cobra.Command
- func NewMakeService(env *Env) *cobra.Command
- func NewMakeTest(env *Env) *cobra.Command
- func NewMigrateFresh(env *Env) *cobra.Command
- func NewMigrateRefresh(env *Env) *cobra.Command
- func NewMigrateReset(env *Env) *cobra.Command
- func NewMigrateRollback(env *Env) *cobra.Command
- func NewMigrateStatus(env *Env) *cobra.Command
- func NewMigrateStep(env *Env) *cobra.Command
- func NewMigrateUp(env *Env) *cobra.Command
- func NewNew(_ *Env) *cobra.Command
- func SetStubFS(filesystem fs.FS)
- func SetStubOverride(stub, path string)
- type Env
- type FieldSpec
- type Paths
- type ProjectConfig
- type ScaffoldOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDB ¶ added in v0.3.0
NewDB returns `db` — a tiny SQL REPL. Each line is exec'd against the active connection; SELECTs render as a tab-aligned table.
func NewDBSeed ¶
NewDBSeed returns `db:seed [SeederName...]`. The default behavior mirrors Laravel: if a DatabaseSeeder is registered, only it runs (it orchestrates the rest via seeder.Call). Otherwise every registered seeder runs in dependency order. Positional args (or --class) override this and run specific seeders instead.
func NewDBShow ¶ added in v0.3.0
NewDBShow returns `db:show` — prints a summary of the active connection: driver, version, schema, table count.
func NewDBTable ¶ added in v0.3.0
NewDBTable returns `db:table <name>` — prints schema info for one table: columns, types, nullability, and (where supported) approximate row count.
func NewDBWipe ¶
NewDBWipe returns `db:wipe` — DROPs every user table. Refuses to run without --force. Useful for tests; not intended for production.
func NewEnv ¶ added in v0.4.0
NewEnv returns `env` — prints the currently active environment variables that drive lagodev (DB_*, APP_*). Sensitive values (PASSWORD, SECRET, KEY) are redacted by default; pass --show-secrets to print them in clear text.
func NewEnvInit ¶ added in v0.4.0
NewEnvInit returns `env:init` — writes a starter .env file with the keys lagodev understands. Refuses to overwrite without --force.
func NewInit ¶ added in v0.2.0
NewInit returns `artisan init` — yangi loyihaning standart skeletini yaratadi: lago.json, config/, routes/ papkalari va sample fayllar.
func NewKeyGenerate ¶ added in v0.14.0
NewKeyGenerate returns `key:generate` — Laravel-style command that produces a base64-encoded 32-byte AES-256 key and either writes it to a .env file (under APP_KEY) or prints it for the caller to capture themselves.
Flags:
--env <path> path to .env (default ".env"); written when present --show print the key to stdout in addition to writing --force overwrite an existing APP_KEY value --print-only print to stdout and do NOT touch any file
func NewMakeCRUD ¶ added in v0.2.0
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 NewMakeController ¶ added in v0.3.0
NewMakeController returns `make:controller` — generates a REST-style HTTP handler set (Index/Show/Store/Update/Destroy) bound to a model. Default output uses stdlib net/http via the `web` package; pass `--framework=gin` to emit a Gin-flavored controller that uses the lagogin adapter (Paginate + BindAndValidate + Resource compatibility).
artisan make:controller PostController --model=Post artisan make:controller PostController --framework=gin
func NewMakeFactory ¶
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 ¶
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 ¶
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 NewMakeScheme ¶ added in v0.19.0
NewMakeScheme returns `lago make:scheme <Name>` — generates a DTO (request / response schema) struct under the project's `schemes/` directory. The Name is normalised to PascalCase; the file name is snake_case.
lago make:scheme StorePost # → schemes/store_post.go
The generated DTO has validate-friendly tags so callers can plug it straight into `c.BindAndValidate(&dst)`.
func NewMakeSeeder ¶
NewMakeSeeder returns the `make:seeder` command.
func NewMakeService ¶ added in v0.4.0
NewMakeService returns `make:service` — generates a framework-agnostic CRUD service for a model. The service is the same regardless of whether the host app uses Gin, Fiber, Echo, Chi, gRPC, or plain net/http; the generated controller (and any custom adapters you write) sits on top.
artisan make:service PostService --model=Post
func NewMakeTest ¶
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 ¶
NewMigrateFresh returns the `migrate:fresh` command (drop all tables + up).
func NewMigrateRefresh ¶
NewMigrateRefresh returns the `migrate:refresh` command (rollback + up).
func NewMigrateReset ¶
NewMigrateReset returns the `migrate:reset` command.
func NewMigrateRollback ¶
NewMigrateRollback returns the `migrate:rollback` command.
func NewMigrateStatus ¶
NewMigrateStatus returns the `migrate:status` command.
func NewMigrateStep ¶
NewMigrateStep returns the `migrate:step` command.
func NewMigrateUp ¶
NewMigrateUp returns the `migrate` command.
func NewNew ¶ added in v0.10.0
NewNew returns `lago new <name>` — scaffolds a fresh project with the canonical Laravel-style layout, an interactive infrastructure picker, and a complete Docker / Kubernetes deploy stack.
lago new myapp # interactive prompts lago new myapp --yes # non-interactive defaults lago new myapp --framework=gin --db=postgres --cache=redis --storage=minio lago new myapp --module=acme/myapp # explicit module path
func SetStubFS ¶
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
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
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
FieldName returns the Go struct field name (PascalCase), e.g. "user_id" → "UserID" — preserving common acronyms via the inflect package.
func (FieldSpec) MigrationCall ¶ added in v0.2.0
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
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:
- The path in $LAGO_CONFIG, if set
- `lago.json` in the current directory
- Built-in defaults (see DefaultPaths)
type ScaffoldOptions ¶ added in v0.19.0
type ScaffoldOptions struct {
Name string // app name, used in env / compose service name
Module string // Go module path
Framework string // "web" | "gin"
Database string // "postgres" | "mysql" | "sqlite" | "none"
Cache string // "redis" | "none"
Storage string // "minio" | "none"
}
ScaffoldOptions captures every interactive choice `lago new` made. The deploy/code stubs are conditional on these fields so the generated project only carries services it actually uses.