runCli function

Future<int> runCli(
  1. List<String> args
)

Single entry point that wraps the CommandRunner with a top-level UsageException catch so unknown options / unknown subcommands turn into a clean exit 64 instead of an uncaught exception with a stack trace.

Use this from bin/*.dart and from tests that want to assert usage-error exit codes. Tests that only exercise valid-arg paths can still call buildCommandRunner().run(...) directly.

Implementation

Future<int> runCli(List<String> args) async {
  try {
    return await buildCommandRunner().run(effectiveArgs(args)) ?? 0;
  } on UsageException catch (e) {
    stderr.writeln(e.message);
    if (e.usage.isNotEmpty) {
      stderr.writeln('');
      stderr.writeln(e.usage);
    }
    return 64;
  }
}