runLiveCustomCommand function
Future<int>
runLiveCustomCommand(
- String name,
- List<
String> arguments, { - LiveRunner? runner,
- LiveOptions? options,
Runs an app-defined live command named name with terminal arguments.
The command's options come from the running app (commands.list), are
parsed by Metro, and the validated values are sent with commands.run.
Implementation
Future<int> runLiveCustomCommand(
String name,
List<String> arguments, {
LiveRunner? runner,
LiveOptions? options,
}) async {
final LiveRunner live = runner ?? LiveRunner();
// Shared flags can sit anywhere among the command's own arguments.
final ({LiveOptions options, List<String> rest}) extracted;
try {
extracted = LiveOptions.extract(expandLiveFileArguments(arguments));
} on FormatException catch (e) {
live.output.error(e.message);
return 64;
}
final LiveOptions resolvedOptions = options ?? extracted.options;
if (_asksForHelp(extracted.rest)) {
return _printCustomCommandHelp(name, extracted.rest, resolvedOptions, live);
}
return live.run(resolvedOptions, (app, block) async {
final LiveCommandSchema schema = await _schemaFor(app, name, live);
final ({Map<String, Object?> values, List<String> rest}) parsed;
try {
parsed = schema.parse(extracted.rest);
} on FormatException catch (e) {
throw LiveCommandException('${e.message}\n\n${schema.usage}');
}
return _runParsed(app, block, name, parsed);
});
}