console

package
v1.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package console runs one-off commands inside the application context: a seed script, a data fix or a report that needs the same services as the app, without starting the HTTP server.

A command is any provider with a Name and a Run method:

type SeedCommand struct{ users *users.Service }

func (c *SeedCommand) Name() string { return "seed" }
func (c *SeedCommand) Run(ctx context.Context, args []string) error { ... }

and main hands its arguments over before it starts the server:

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

dygo generate command writes both.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknown = errors.New("unknown command")

ErrUnknown is returned for a name no command has.

Functions

func Main

func Main(ctx context.Context, root *dygo.Module, args []string, opts ...dygo.Option) int

Main is Run for main: it prints an error and returns the exit status.

func Run

func Run(ctx context.Context, root *dygo.Module, args []string, opts ...dygo.Option) error

Run builds the application context from root, runs the command named by args[0] with the rest of args, and shuts the context down, so lifecycle hooks run as they do for the server. "help" lists the commands.

Types

type Command

type Command interface {
	// Name is the first argument that selects the command: "seed".
	Name() string
	// Run gets the remaining arguments. ctx is cancelled on SIGINT or SIGTERM.
	Run(ctx context.Context, args []string) error
}

Command is a provider that can run from the command line.

type Describer

type Describer interface {
	Description() string
}

Describer is an optional one-line description shown by help.

Jump to

Keyboard shortcuts

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