parse method Null safety

ArgResults parse(
  1. Iterable<String> args

Parses args and returns the result, converting an ArgParserException to a UsageException.

This is notionally a protected method. It may be overridden or called from subclasses, but it shouldn't be called externally.


ArgResults parse(Iterable<String> args) {
  try {
    return argParser.parse(args);
  } on ArgParserException catch (error) {
    if (error.commands.isEmpty) usageException(error.message);

    var command = commands[error.commands.first]!;
    for (var commandName in error.commands.skip(1)) {
      command = command.subcommands[commandName]!;