parse method

ArgResults parse(
  1. Iterable<String> args
)
inherited

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.

Implementation

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]!;
    }

    command.usageException(error.message);
  }
}