Skip to main content

CLI & Runbook

A professional application often needs a command-line interface (CLI) for administrative tasks like starting the server, running migrations, or seeding the database. We use Artisanal to build a Laravel-style CLI for our movie catalog.

Artisanal CLI

The CLI is defined in bin/cli.dart. It uses a command-based structure where each task is a separate command.

The entry point initializes the CLI and registers the available commands.

Future<void> main(List<String> args) async {
final runner =
CommandRunner(
'movie-catalog',
'CLI for the Ormed + Shelf movie catalog example.',
)
..addCommand(ServeCommand())
..addCommand(MigrateCommand())
..addCommand(SeedCommand());

await runner.run(args);
}

Runbook

Here's a quick reference for the common commands you'll use during development:

1. Code Generation

Run this whenever you change your models or add new ones.

dart run build_runner build --delete-conflicting-outputs

2. Database Setup

Prepare your database by running migrations and seeding it with data.

# Apply all pending migrations
dart run ormed_cli:ormed migrate

# Run the database seeders
dart run ormed_cli:ormed seed

3. Running Tests

Ensure everything is working correctly.

dart test

4. Starting the Server

You can start the server directly or via the Artisanal CLI.

# Start server directly
dart run bin/server.dart

# Start server using the CLI (recommended)
dart run bin/cli.dart serve