run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
final args = argResults!;
final rest = args.rest;
if (rest.isEmpty) throw CliError('usage: node logs <id> [-f]');
final node = rest.first;
final client = _apiClientFrom(args);
try {
final lines = await client.logs(
node,
tail: int.tryParse(args['tail'] as String) ?? 200,
);
if (lines.isEmpty && !(args['follow'] as bool)) {
stdout.writeln(
'no logs from $node yet '
'(the node must run with --ship-logs, which is the default)',
);
return;
}
for (final line in lines) {
stdout.writeln(_render(line));
}
} finally {
client.close();
}
if (args['follow'] as bool) {
// The stream is raw SSE frames, not the typed client — there is no
// typed streaming yet, and a follow that decoded differently from the
// tail above would print two formats in one run.
await _streamSse(
args,
'/api/v1/nodes/$node/logs/stream',
onEvent: (payload) => stdout.writeln(
_render(LogLine.fromJson(payload.cast<String, dynamic>())),
),
);
}
}