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 NewDBSeed(env *Env) *cobra.Command
- func NewDBWipe(env *Env) *cobra.Command
- func NewMakeFactory(env *Env) *cobra.Command
- func NewMakeMigration(env *Env) *cobra.Command
- func NewMakeModel(env *Env) *cobra.Command
- func NewMakeSeeder(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 SetStubFS(filesystem fs.FS)
- func SetStubOverride(stub, path string)
- type Env
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDBSeed ¶
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 ¶
NewDBWipe returns `db:wipe` — DROPs every user table. Refuses to run without --force. Useful for tests; not intended for production.
func NewMakeFactory ¶
NewMakeFactory returns the `make:factory` command.
artisan make:factory UserFactory --model=User artisan make:factory UserFactory --model=User --model-dir=models
If --model is omitted, the model name is derived from the factory name (strip trailing "Factory"). When --model-dir differs from --dir, the generator imports the model package automatically using the host project's go.mod module path.
func NewMakeMigration ¶
NewMakeMigration returns the `make:migration` command.
artisan make:migration create_users_table artisan make:migration add_email_to_users --table=users
The generator infers the target table from the migration name when it matches conventional patterns (create_X_table / add_X_to_Y / drop_X_table).
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 -mf shorthand for -m -f, etc. --dir overrides the output directory (default: models/) --force overwrites existing files
func NewMakeSeeder ¶
NewMakeSeeder returns the `make:seeder` command.
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 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.