parseOptions function

Future<DartdocProgramOptionContext> parseOptions (
  1. PackageMetaProvider packageMetaProvider,
  2. List<String> arguments,
  3. {OptionGenerator additionalOptions}
)

Implementation

Future<DartdocProgramOptionContext> parseOptions(
  PackageMetaProvider packageMetaProvider,
  List<String> arguments, {
  OptionGenerator additionalOptions,
}) async {
  var optionSet = await DartdocOptionSet.fromOptionGenerators(
      'dartdoc',
      [
        createDartdocOptions,
        createDartdocProgramOptions,
        createLoggingOptions,
        createGeneratorOptions,
        if (additionalOptions != null) additionalOptions,
      ],
      packageMetaProvider);

  try {
    optionSet.parseArguments(arguments);
  } on FormatException catch (e) {
    stderr.writeln(' fatal error: ${e.message}');
    stderr.writeln('');
    _printUsage(optionSet.argParser);
    // Do not use exit() as this bypasses --pause-isolates-on-exit
    exitCode = 64;
    return null;
  }
  if (optionSet['help'].valueAtCurrent()) {
    _printHelp(optionSet.argParser);
    exitCode = 0;
    return null;
  }
  if (optionSet['version'].valueAtCurrent()) {
    _printVersion(optionSet.argParser);
    exitCode = 0;
    return null;
  }

  DartdocProgramOptionContext config;
  try {
    config = DartdocProgramOptionContext(
        optionSet, null, packageMetaProvider.resourceProvider);
  } on DartdocOptionError catch (e) {
    stderr.writeln(' fatal error: ${e.message}');
    stderr.writeln('');
    await stderr.flush();
    _printUsage(optionSet.argParser);
    exitCode = 64;
    return null;
  }
  startLogging(config);
  return config;
}