liveRunUsage function
The metro live:run help: the built-in actions, then the project's live
commands from commands.json.
Implementation
String liveRunUsage(List<LiveManifestEntry> projectCommands) {
final List<LiveManifestEntry> sorted = List<LiveManifestEntry>.of(
projectCommands,
)..sort((a, b) => a.fullName.compareTo(b.fullName));
final int width = [
...liveRunActions.keys,
...sorted.map((entry) => entry.fullName),
].map((name) => name.length).reduce((a, b) => a > b ? a : b);
final StringBuffer buffer = StringBuffer()
..writeln('Usage: metro live:run <command> [arguments]')
..writeln()
..writeln('Built-in commands:');
for (final MapEntry<String, LiveRunAction> action in liveRunActions.entries) {
buffer.writeln(
' ${action.key.padRight(width + 2)}${action.value.description}',
);
}
buffer
..writeln()
..writeln('Your commands (lib/app/commands):');
if (sorted.isEmpty) {
buffer.writeln(
' None yet. Create one with: metro make:command seed_cart --live',
);
}
for (final LiveManifestEntry entry in sorted) {
buffer.writeln(
' ${entry.fullName.padRight(width + 2)}${entry.description ?? ''}'
.trimRight(),
);
}
buffer
..writeln()
..writeln('Run metro live:run <command> --help for its options.')
..writeln()
..writeln('Options for every command:')
..write(LiveOptions.usage.split('\n').map((line) => ' $line').join('\n'));
return buffer.toString();
}