Skip to content

Console commands

Terminalsh
dygo g command seed # seed/command.go, registered in the nearest module
dygo run seed --users 10 # builds the app and runs the command inside its context
dygo run # lists the commands with their descriptions

A command is a provider with Name() and Run(ctx, args) (and optionally Description()), so it can inject any service. Package console builds the application context, runs the command, then shuts down, so OnModuleInit and shutdown hooks run as they do for the server. ctx is cancelled on Ctrl+C. New projects’ main.go starts with:

if len(os.Args) > 1 { // go run . <command>
os.Exit(console.Main(ctx, AppModule(cfg, log), os.Args[1:], dygo.WithLogger(log)))
}

In a project made before this existed, dygo g command prints that snippet.