Help us shape the future of Go! Take the 2026 Go Developer Survey

cmd

package
v0.1.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: 17 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 NewMakeFactory

func NewMakeFactory(env *Env) *cobra.Command

NewMakeFactory returns the `make:factory` command.

artisan make:factory UserFactory --model=User

If --model is omitted, the model name is derived from the factory name (strip trailing "Factory").

func NewMakeMigration

func NewMakeMigration(env *Env) *cobra.Command

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

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
-mf  shorthand for -m -f, etc.
--dir overrides the output directory (default: models/)
--force overwrites existing files

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.

Jump to

Keyboard shortcuts

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