LiveCommand class abstract
A command that runs inside your running app, triggered from Metro.
Live commands live in lib/app/commands/ next to your Metro commands and
use the same builder and handle shape. The difference is where they
run: handle executes inside the app, so it can use NyStorage,
routeTo, Auth and your models.
class SeedCartCommand extends LiveCommand {
@override
CommandBuilder builder(CommandBuilder command) {
command.addOption('count', abbr: 'c', defaultValue: '3');
command.addFlag('open', help: 'Open the cart afterwards');
return command;
}
@override
Future<void> handle(CommandResult result) async {
final int count = result.getInt('count') ?? 3;
await CartItem.seed(count: count);
success('Seeded $count cart items');
}
}
Create one with metro make:command seed_cart --live, which also registers
it with your app, then run it from the terminal while the app runs in debug
mode: metro app:seed_cart --count 5.
- Mixed-in types
Constructors
Properties
- description → String?
-
A one-line description, shown by the command's
--help.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
-
output
→ List<
Map< String, String> > -
The lines written with info, success, warning, error and line.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
builder(
CommandBuilder command) → CommandBuilder - Declare the options and flags this command accepts.
-
error(
String message) → void -
Write an error line to the terminal.
inherited
-
handle(
CommandResult result) → Future - Runs inside the app when the command is called from Metro.
-
info(
String message) → void -
Write an informational line to the terminal.
inherited
-
line(
String message) → void -
Write a plain line to the terminal.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
seed(
List< Seeder> seeders) → Future<void> -
Runs each seeder's
up()in order, and shows what they changed. -
success(
String message) → void -
Write a success line to the terminal.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
warning(
String message) → void -
Write a warning line to the terminal.
inherited
-
writeOutput(
Map< String, String> entry) → void -
Adds
entry(alevelandmessage) to output.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited