跳转至正文

Commands ​

Introduction ​

A PrismGo application's main.go passes os.Args to app.HandleCommand. In the project root, commands are usually run with go run .:

bash
go run . list
go run . serve
go run . migrate

If you use a compiled binary, replace go run . with your binary name.

Listing Commands ​

CommandDescription
go run . listList all available commands
go run . list makeFilter by namespace
go run . list --format=jsonOutput JSON
go run . list --format=mdOutput Markdown
go run . list --rawPrint ungrouped raw command names and descriptions
go run . help migrateShow help for one command

HTTP Server Commands ​

serve starts or controls the built-in HTTP server. See HTTP Server for configuration.

CommandDescription
go run . serveStart the HTTP server from .env / config/app.go
go run . serve --port=8000Temporarily override the listen port
go run . serve --reloadStart a new process, then gracefully stop the old one
go run . serve --restartKill the old process, then start a new one
go run . serve --stopGracefully stop the server on the current port
go run . serve --killForce stop the server on the current port

make Generators ​

PrismGo provides Laravel-style make:* commands. All generators support:

OptionDescription
{name}Artifact name, optionally nested, such as Admin/UserController
--forceOverwrite an existing file
--fullpathPrint an absolute path

Generator List ​

CommandDefault DirectoryDescription
make:commandapp/cmdCreate a Console command
make:controllerapp/http/controllersCreate an HTTP controller
make:eventapp/eventsCreate an event
make:jobapp/jobsCreate a queued job
make:listenerapp/listenersCreate an event listener
make:middlewareapp/http/middlewareCreate Gin middleware
make:migrationdatabase/migrationsCreate a migration
make:modelapp/modelsCreate a GORM model
make:providerapp/providersCreate a service provider
make:resourceapp/http/resourcesCreate an API resource transformer
make:seederdatabase/seedersCreate a seeder

Common Examples ​

bash
go run . make:controller UserController
go run . make:model User --migration --controller --resource
go run . make:job SendWelcomeEmail
go run . make:listener SendWelcomeEmail --queued --event=UserRegistered
go run . make:provider BillingServiceProvider

make:model can create related artifacts:

OptionDescription
-m, --migrationAlso create a create_<model>s_table migration
-c, --controllerAlso create a controller
-r, --resourceAlso create an API resource
-s, --seeder / --seedAlso create a seeder
--apiCreate an API controller; also creates a controller if --controller is not set
--table=Pass a table-name hint into the generation flow

make:model currently rejects --factory, --policy, --requests, --all, --test, --pest, --pivot, and --morph-pivot.

make:controller supports:

OptionDescription
-m, --model=Add a model TODO to the generated file; imports are not inferred
--apiGenerate an API-style controller
-r, --resourceGenerate a resource-style controller

make:command supports:

OptionDescription
--command=Override the generated command signature

Example:

bash
go run . make:command Report/DailyReportCommand --command=report:daily

make:listener supports:

OptionDescription
--queuedGenerate a queued listener
--asyncGenerate an async listener
--event=Write an event hint into the generated file

--queued and --async are mutually exclusive.

make:migration supports:

OptionDescription
--create=Generate a create-table migration and set the table name
--table=Generate an alter-table migration and set the table name
--path=Use a custom migration directory
--realpathAllow --path to be an absolute path
bash
go run . make:migration create_users_table --create=users
go run . make:migration add_avatar_to_users_table --table=users

When --create or --table is omitted, the generator infers intent from the migration name.

Custom Generator Stubs ​

Publish the built-in stubs:

bash
go run . stub:publish

Generators prefer project stubs under stubs/*.stub. Existing files are skipped by default; use --force to overwrite:

bash
go run . stub:publish --force

Database Migration Commands ​

Migration commands scan the migration paths registered in bootstrap/app.go. New applications import database/migrations by default.

CommandDescription
go run . migrateRun pending migrations
go run . migrate:installCreate the migration metadata table
go run . migrate:statusShow migration status
go run . migrate:rollbackRoll back the latest batch
go run . migrate:resetRoll back all migrations
go run . migrate:refreshRoll back and re-run migrations
go run . migrate:freshDrop all tables and re-run migrations
go run . db:seedRun a seeder

Common options:

OptionCommandsDescription
--database=All migration commands, db:seedUse a specific database connection
--forceCommands that modify dataAllow running in production
--path=*Migration commandsMigration file directories; may be repeated
--realpathMigration commandsTreat --path as an absolute path
--pretendmigrate, rollback/reset/refreshPrint operations without changing data
--seedmigrate, refresh/freshRun seeders after migrations
--seeder=migrate, refresh/freshRoot seeder class
--stepmigratePut each migration in its own batch
--step=rollback/refreshRoll back a specific number of migrations
--batch=rollbackRoll back a specific batch
--drop-viewsfreshDrop views
--drop-typesfreshDrop Postgres enum/type objects
--class=db:seedSeeder class

Production protection is driven by app.env / APP_ENV. In production, commands that modify data require --force.

SQLite requires the github.com/prismgo/sqlite extension to be installed and registered first. migrate:fresh delegates object removal to the active Dialector: for SQLite it drops views when --drop-views is supplied, drops all user tables, and then runs migrations. The command and its options are otherwise the same as for MySQL.

Queue Commands ​

CommandDescription
go run . queueStart a queue worker
go run . queue:workAlias for queue
go run . queue:failedList failed jobs
go run . queue:retry <id...>Retry failed jobs
go run . queue:forget <id>Delete one failed job
go run . queue:flushDelete all failed jobs
go run . queue:restartAsk workers to restart gracefully

Worker options:

OptionDefaultDescription
{connection?}queue.defaultQueue connection
--queue=defaultQueue names, comma-separated
--oncefalseProcess one job
--stop-when-emptyfalseExit when queues are empty
--sleep=3Sleep seconds when queues are empty
--timeout=60Per-job timeout seconds
--tries=1Maximum attempts
--backoff=0Retry backoff seconds, comma-separated
--max-jobs=0Exit after N jobs; 0 means unlimited
--max-time=0Exit after N seconds; 0 means unlimited
--retry-after=90Redis reserved-job visibility timeout for this worker; overrides the connection setting

Scheduler Command ​

bash
go run . cron

cron registers the r.Schedules(...) callback from bootstrap/app.go and runs until the application context closes or the process receives SIGINT / SIGTERM.

Key and Stub Commands ​

Generate an application key:

bash
go run . key:generate
OptionDescription
--showPrint a new key without editing .env
--forceOverwrite an existing APP_KEY

key:generate creates a base64: value containing 32 random bytes and writes it to the APP_KEY= line in .env. See Encryption.