run method
Runs the command name with args: {ok: true, result} or {ok: false, error}.
Implementation
Future<Map<String, Object?>> run(
String name, [
Map<String, Object?>? args,
]) async {
args ??= const <String, Object?>{};
try {
final result = switch (name) {
_menuCommand => _menu(args),
_lineCommand => await _line(args),
_ => throw _AgentError(
'unknown command "$name" ($_menuCommand, $_lineCommand)',
),
};
return {'ok': true, 'result': result};
} on _AgentError catch (e) {
return {'ok': false, 'error': e.message};
} catch (e) {
return {'ok': false, 'error': '$e'};
}
}