run method

  1. @nonVirtual
FutureOr<bool> run()

Run

Implementation

@nonVirtual
FutureOr<bool> run() async {
  // Handle version first
  if (parent == null) {
    // Handle verbose
    _verbose = getFlag(flagVerbose);

    final hasVersion = getFlag(flagVersion);
    if (hasVersion) {
      stdout.writeln(version);
      return true;
    }
  }
  // Handle help
  final help = results[flagHelp] as bool;

  if (help) {
    printUsage();
    return true;
  }

  // Find the command if any
  var command = results.command;

  var shellCommand = _commands[command?.name];
  if (shellCommand != null) {
    // Set the result in the the shell command
    shellCommand.results = command!;
    return shellCommand.run();
  }

  var ran = await onRun();
  if (!ran) {
    stderr.writeln('No command ran');
    printBaseUsage();
    exit(1);
  }
  return ran;
}