parseOptions function

Options parseOptions(
  1. List<String> args
)

Parse the given args, setting the options as appropriate and returning the tasks the user requested to run.

This method may be called several times with the same arguments without actually parsing them again as the results of a first invocation are cached, allowing different entry points of the library to call this method to initialize the user options without re-parsing arguments every time.

Implementation

Options parseOptions(List<String> args) {
  ArgResults parseResult;
  try {
    parseResult = _parser.parse(args);
  } on FormatException catch (e) {
    throw DartleException(
        message: '${e.message}.. run with the -h flag to see usage.',
        exitCode: 4);
  }

  if (parseResult.wasParsed('help')) {
    return const Options(showHelp: true);
  }
  if (parseResult.wasParsed('version')) {
    return const Options(showVersion: true);
  }
  var colorOption = parseResult['color'] as bool;
  if (!parseResult.wasParsed('color') && isNoColorEnvVarSet()) {
    colorOption = false;
  }

  return Options(
    logLevel: _parseLogLevel(parseResult['log-level'].toString()),
    colorfulLog: colorOption,
    forceTasks: parseResult['force-tasks'] as bool,
    parallelizeTasks: parseResult['parallel-tasks'] as bool,
    showTasks: parseResult['show-tasks'] as bool,
    showTaskGraph: parseResult['show-task-graph'] as bool,
    resetCache: parseResult['reset-cache'] as bool,
    logBuildTime: parseResult['log-build-time'] as bool,
    runPubGet: parseResult['run-pub-get'] as bool,
    disableCache: parseResult['disable-cache'] as bool,
    tasksInvocation: parseResult.rest,
  );
}