Galaplate includes a powerful console command system that provides code generation, database management, and custom command capabilities. All console commands are executed through the main application entry point.
# General syntax
go run main.go console <command> [arguments]
# List all available commands
go run main.go console list
# Get help
go run main.go console
db:createCreate a new database migration file.
go run main.go console db:create create_users_table
db:upRun pending database migrations.
go run main.go console db:up
db:downRollback the last database migration.
go run main.go console db:down
db:statusShow current migration status.
go run main.go console db:status
db:freshDrop all tables and re-run all migrations.
go run main.go console db:fresh
db:resetRollback all migrations and re-run them.
go run main.go console db:reset
db:seedRun database seeders.
go run main.go console db:seed
make:modelGenerate a new model file.
go run main.go console make:model User
Generated file: pkg/models/user.go
Example output:
package models
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}
make:dtoGenerate a new Data Transfer Object (DTO).
go run main.go console make:dto UserDto
Generated file: pkg/dto/user_dto.go
make:jobGenerate a new background job.
go run main.go console make:job ProcessEmailJob
Generated file: pkg/queue/jobs/process_email_job.go
make:seederGenerate a new database seeder.
go run main.go console make:seeder UserSeeder
Generated file: db/seeders/user_seeder.go
make:cronGenerate a new cron job for the scheduler.
go run main.go console make:cron DailyReportCron
Generated file: pkg/scheduler/daily_report_cron.go
listDisplay all available console commands with descriptions.
go run main.go console list
exampleRun an example command to test the console system.
go run main.go console example
interactiveStart an interactive demonstration of console features.
go run main.go console interactive
Create a new command file in pkg/console/commands/:
// pkg/console/commands/my_custom_command.go
package commands
import (
"fmt"
)
type MyCustomCommand struct{}
func (c *MyCustomCommand) GetSignature() string {
return "my:custom"
}
func (c *MyCustomCommand) GetDescription() string {
return "My custom command description"
}
func (c *MyCustomCommand) Execute(args []string) error {
fmt.Println("Executing my custom command!")
if len(args) > 0 {
fmt.Printf("Arguments: %v\n", args)
}
return nil
}
Add your command to the registration in pkg/console/commands.go:
func (k *Kernel) RegisterCommands() {
// Example command (you can remove this)
k.Register(&commands.ExampleCommand{})
// Interactive demo command
k.Register(&commands.InteractiveCommand{})
// Register your custom command
k.Register(&commands.MyCustomCommand{})
}
go run main.go console my:custom arg1 arg2
All commands must implement the Command interface:
type Command interface {
GetSignature() string // Command name (e.g., "make:model")
GetDescription() string // Brief description for help
Execute(args []string) error // Command logic
}
: to separate command namespaces (e.g., make:model, db:up)cache:clear)Execute()type DeployCommand struct{}
func (c *DeployCommand) GetSignature() string {
return "deploy"
}
func (c *DeployCommand) GetDescription() string {
return "Deploy application to specified environment"
}
func (c *DeployCommand) Execute(args []string) error {
if len(args) < 1 {
return fmt.Errorf("environment required. Usage: deploy <environment>")
}
environment := args[0]
fmt.Printf("Deploying to %s environment...\n", environment)
// Your deployment logic here
fmt.Printf("Successfully deployed to %s!\n", environment)
return nil
}
Console commands work alongside traditional Make commands:
# These are equivalent:
go run main.go console db:up
# These are equivalent:
go run main.go console make:model User
# (No direct make equivalent for code generation)
Console commands automatically load your .env configuration:
func (c *MyCommand) Execute(args []string) error {
// Environment variables are available
dbHost := os.Getenv("DB_HOST")
appName := os.Getenv("APP_NAME")
// Your command logic
return nil
}
Enable verbose output for debugging:
# Set debug mode in .env
APP_DEBUG=true
# Run your command
go run main.go console my:command
Next Steps: