Skip to content

Remove unused additionalOptions parameter, other little refactorings #3339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions lib/options.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:io' show stderr, exitCode;

import 'package:analyzer/file_system/file_system.dart';
import 'package:args/args.dart';
import 'package:dartdoc/dartdoc.dart' show dartdocVersion, programName;
import 'package:dartdoc/src/dartdoc_options.dart';
Expand All @@ -11,22 +10,21 @@ import 'package:dartdoc/src/package_meta.dart';
/// Helper class that consolidates option contexts for instantiating generators.
class DartdocGeneratorOptionContext extends DartdocOptionContext {
DartdocGeneratorOptionContext(
super.optionSet, Folder super.dir, super.resourceProvider);
super.optionSet, super.dir, super.resourceProvider);
DartdocGeneratorOptionContext.fromDefaultContextLocation(
super.optionSet, super.resourceProvider)
: super.fromDefaultContextLocation();

/// Returns the joined contents of any 'header' files specified in options.
late final String header =
/// The joined contents of any 'header' files specified in options.
String get header =>
_joinCustomTextFiles(optionSet['header'].valueAt(context));

/// Returns the joined contents of any 'footer' files specified in options.
late final String footer =
/// The joined contents of any 'footer' files specified in options.
String get footer =>
_joinCustomTextFiles(optionSet['footer'].valueAt(context));

/// Returns the joined contents of any 'footer-text' files specified in
/// options.
late final String footerText =
/// The joined contents of any 'footer-text' files specified in options.
String get footerText =>
_joinCustomTextFiles(optionSet['footerText'].valueAt(context));

String _joinCustomTextFiles(Iterable<String> paths) => paths
Expand All @@ -40,21 +38,20 @@ class DartdocGeneratorOptionContext extends DartdocOptionContext {
String? get relCanonicalPrefix =>
optionSet['relCanonicalPrefix'].valueAt(context);

/// The 'templatesDir' dartdoc option if one was specified; otherwise `null`.
String? get templatesDir => optionSet['templatesDir'].valueAt(context);

// TODO(jdkoren): duplicated temporarily so that GeneratorContext is enough for configuration.
@override
bool get useBaseHref => optionSet['useBaseHref'].valueAt(context);

/// The 'resourcesDir' dartdoc option if one was specified; otherwise `null`.
String? get resourcesDir => optionSet['resourcesDir'].valueAt(context);
}

class DartdocProgramOptionContext extends DartdocGeneratorOptionContext
with LoggingContext {
DartdocProgramOptionContext(
super.optionSet, super.dir, super.resourceProvider);

DartdocProgramOptionContext.fromDefaultContextLocation(
super.optionSet, super.resourceProvider)
: super.fromDefaultContextLocation();
Expand Down Expand Up @@ -82,17 +79,15 @@ List<DartdocOption<bool>> createDartdocProgramOptions(

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

Expand All @@ -102,7 +97,7 @@ DartdocProgramOptionContext? parseOptions(
stderr.writeln(' fatal error: ${e.message}');
stderr.writeln('');
_printUsage(optionRoot.argParser);
// Do not use exit() as this bypasses --pause-isolates-on-exit
// Do not use `exit()` as this bypasses `--pause-isolates-on-exit`.
exitCode = 64;
return null;
}
Expand Down