@@ -433,6 +433,17 @@ class _YamlFileData {
433433 _YamlFileData (this .data, this .canonicalDirectoryPath);
434434}
435435
436+ /// An enum to specify the multiple different kinds of data an option might
437+ /// represent.
438+ enum OptionKind {
439+ other, // Make no assumptions about the option data; it may be of any type
440+ // or semantic.
441+ file, // Option data references a filename or filenames with strings.
442+ dir, // Option data references a directory name or names with strings.
443+ glob, // Option data references globs with strings that may cover many
444+ // filenames and/or directories.
445+ }
446+
436447/// Some DartdocOption subclasses need to keep track of where they
437448/// got the value from; this class contains those intermediate results
438449/// so that error messages can be more useful.
@@ -503,10 +514,15 @@ abstract class DartdocOption<T> {
503514 final String name;
504515
505516 /// Set to true if this option represents the name of a directory.
506- final bool isDir;
517+ bool get isDir => optionIs == OptionKind .dir ;
507518
508519 /// Set to true if this option represents the name of a file.
509- final bool isFile;
520+ bool get isFile => optionIs == OptionKind .file;
521+
522+ /// Set to true if this option represents a glob.
523+ bool get isGlob => optionIs == OptionKind .glob;
524+
525+ final OptionKind optionIs;
510526
511527 /// Set to true if DartdocOption subclasses should validate that the
512528 /// directory or file exists. Does not imply validation of [defaultsTo] ,
@@ -515,11 +531,13 @@ abstract class DartdocOption<T> {
515531
516532 final ResourceProvider resourceProvider;
517533
518- DartdocOption (this .name, this .defaultsTo, this .help, this .isDir, this .isFile ,
534+ DartdocOption (this .name, this .defaultsTo, this .help, this .optionIs ,
519535 this .mustExist, this ._convertYamlToType, this .resourceProvider) {
520- assert (! (isDir && isFile));
521- if (isDir || isFile) assert (_isString || _isListString || _isMapString);
536+ if (isDir || isFile || isGlob) {
537+ assert (_isString || _isListString || _isMapString);
538+ }
522539 if (mustExist) {
540+ // Globs by definition don't have to exist.
523541 assert (isDir || isFile);
524542 }
525543 }
@@ -604,7 +622,7 @@ abstract class DartdocOption<T> {
604622 /// For a [List<String>] or [String] value, if [isDir] or [isFile] is set,
605623 /// resolve paths in value relative to canonicalPath.
606624 T _handlePathsInContext (_OptionValueWithContext <Object > valueWithContext) {
607- if (valueWithContext? .value == null || ! (isDir || isFile)) {
625+ if (valueWithContext? .value == null || ! (isDir || isFile || isGlob )) {
608626 return valueWithContext? .value;
609627 }
610628 _validatePaths (valueWithContext);
@@ -715,11 +733,10 @@ class DartdocOptionFileSynth<T> extends DartdocOption<T>
715733 String name, this ._compute, ResourceProvider resourceprovider,
716734 {bool mustExist = false ,
717735 String help = '' ,
718- bool isDir = false ,
719- bool isFile = false ,
736+ OptionKind optionIs = OptionKind .other,
720737 bool parentDirOverridesChild,
721738 ConvertYamlToType <T > convertYamlToType})
722- : super (name, null , help, isDir, isFile , mustExist, convertYamlToType,
739+ : super (name, null , help, optionIs , mustExist, convertYamlToType,
723740 resourceprovider) {
724741 _parentDirOverridesChild = parentDirOverridesChild;
725742 }
@@ -765,12 +782,10 @@ class DartdocOptionArgSynth<T> extends DartdocOption<T>
765782 bool mustExist = false ,
766783 String help = '' ,
767784 bool hide = false ,
768- bool isDir = false ,
769- bool isFile = false ,
785+ OptionKind optionIs = OptionKind .other,
770786 bool negatable = false ,
771787 bool splitCommas})
772- : super (name, null , help, isDir, isFile, mustExist, null ,
773- resourceProvider) {
788+ : super (name, null , help, optionIs, mustExist, null , resourceProvider) {
774789 _hide = hide;
775790 _negatable = negatable;
776791 _splitCommas = splitCommas;
@@ -818,10 +833,8 @@ class DartdocOptionSyntheticOnly<T> extends DartdocOption<T>
818833 String name, this ._compute, ResourceProvider resourceProvider,
819834 {bool mustExist = false ,
820835 String help = '' ,
821- bool isDir = false ,
822- bool isFile = false })
823- : super (
824- name, null , help, isDir, isFile, mustExist, null , resourceProvider);
836+ OptionKind optionIs = OptionKind .other})
837+ : super (name, null , help, optionIs, mustExist, null , resourceProvider);
825838}
826839
827840abstract class DartdocSyntheticOption <T > implements DartdocOption <T > {
@@ -856,7 +869,8 @@ typedef OptionGenerator = Future<List<DartdocOption<Object>>> Function(
856869/// option itself.
857870class DartdocOptionSet extends DartdocOption <void > {
858871 DartdocOptionSet (String name, ResourceProvider resourceProvider)
859- : super (name, null , null , false , false , false , null , resourceProvider);
872+ : super (
873+ name, null , null , OptionKind .other, false , null , resourceProvider);
860874
861875 /// Asynchronous factory that is the main entry point to initialize Dartdoc
862876 /// options for use.
@@ -908,11 +922,10 @@ class DartdocOptionArgOnly<T> extends DartdocOption<T>
908922 bool mustExist = false ,
909923 String help = '' ,
910924 bool hide = false ,
911- bool isDir = false ,
912- bool isFile = false ,
925+ OptionKind optionIs = OptionKind .other,
913926 bool negatable = false ,
914927 bool splitCommas})
915- : super (name, defaultsTo, help, isDir, isFile , mustExist, null ,
928+ : super (name, defaultsTo, help, optionIs , mustExist, null ,
916929 resourceProvider) {
917930 _hide = hide;
918931 _negatable = negatable;
@@ -949,12 +962,11 @@ class DartdocOptionArgFile<T> extends DartdocOption<T>
949962 bool mustExist = false ,
950963 String help = '' ,
951964 bool hide = false ,
952- bool isDir = false ,
953- bool isFile = false ,
965+ OptionKind optionIs = OptionKind .other,
954966 bool negatable = false ,
955967 bool parentDirOverridesChild = false ,
956968 bool splitCommas})
957- : super (name, defaultsTo, help, isDir, isFile , mustExist, null ,
969+ : super (name, defaultsTo, help, optionIs , mustExist, null ,
958970 resourceProvider) {
959971 _abbr = abbr;
960972 _hide = hide;
@@ -1007,12 +1019,11 @@ class DartdocOptionFileOnly<T> extends DartdocOption<T>
10071019 String name, T defaultsTo, ResourceProvider resourceProvider,
10081020 {bool mustExist = false ,
10091021 String help = '' ,
1010- bool isDir = false ,
1011- bool isFile = false ,
1022+ OptionKind optionIs = OptionKind .other,
10121023 bool parentDirOverridesChild = false ,
10131024 ConvertYamlToType <T > convertYamlToType})
1014- : super (name, defaultsTo, help, isDir, isFile, mustExist ,
1015- convertYamlToType, resourceProvider) {
1025+ : super (name, defaultsTo, help, optionIs, mustExist, convertYamlToType ,
1026+ resourceProvider) {
10161027 _parentDirOverridesChild = parentDirOverridesChild;
10171028 }
10181029
@@ -1260,8 +1271,10 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
12601271
12611272 T retval;
12621273 // Unlike in _DartdocFileOption, we throw here on inputs being invalid
1263- // rather than silently proceeding. TODO(jcollins-g): throw on input
1264- // formatting for files too?
1274+ // rather than silently proceeding. This is because the user presumably
1275+ // typed something wrong on the command line and can therefore fix it.
1276+ // dartdoc_option.yaml files from other packages may not be fully in the
1277+ // user's control.
12651278 if (_isBool || _isListString || _isString) {
12661279 retval = _argResults[argName];
12671280 } else if (_isInt) {
@@ -1566,7 +1579,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
15661579 }, resourceProvider,
15671580 help: 'Remove text from libraries with the following names.' ),
15681581 DartdocOptionArgFile <String >('examplePathPrefix' , null , resourceProvider,
1569- isDir : true ,
1582+ optionIs : OptionKind .dir ,
15701583 help: 'Prefix for @example paths.\n (defaults to the project root)' ,
15711584 mustExist: true ),
15721585 DartdocOptionArgFile <List <String >>('exclude' , [], resourceProvider,
@@ -1580,7 +1593,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
15801593 (DartdocSyntheticOption <String > option, Folder dir) =>
15811594 resolveTildePath (Platform .environment['FLUTTER_ROOT' ]),
15821595 resourceProvider,
1583- isDir : true ,
1596+ optionIs : OptionKind .dir ,
15841597 help: 'Root of the Flutter SDK, specified from environment.' ,
15851598 mustExist: true ),
15861599 DartdocOptionArgOnly <bool >('hideSdkText' , false , resourceProvider,
@@ -1592,7 +1605,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
15921605 help: 'Library names to generate docs for.' , splitCommas: true ),
15931606 DartdocOptionArgFile <List <String >>(
15941607 'includeExternal' , null , resourceProvider,
1595- isFile : true ,
1608+ optionIs : OptionKind .file ,
15961609 help:
15971610 'Additional (external) dart files to include; use "dir/fileName", '
15981611 'as in lib/material.dart.' ,
@@ -1605,7 +1618,9 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
16051618 'HTML into dartdoc output.' ),
16061619 DartdocOptionArgOnly <String >(
16071620 'input' , resourceProvider.pathContext.current, resourceProvider,
1608- isDir: true , help: 'Path to source directory' , mustExist: true ),
1621+ optionIs: OptionKind .dir,
1622+ help: 'Path to source directory' ,
1623+ mustExist: true ),
16091624 DartdocOptionSyntheticOnly <String >('inputDir' ,
16101625 (DartdocSyntheticOption <String > option, Folder dir) {
16111626 if (option.parent['sdkDocs' ].valueAt (dir)) {
@@ -1614,7 +1629,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
16141629 return option.parent['input' ].valueAt (dir);
16151630 }, resourceProvider,
16161631 help: 'Path to source directory (with override if --sdk-docs)' ,
1617- isDir : true ,
1632+ optionIs : OptionKind .dir ,
16181633 mustExist: true ),
16191634 DartdocOptionSet ('linkTo' , resourceProvider)
16201635 ..addAll ([
@@ -1656,7 +1671,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
16561671 ]),
16571672 DartdocOptionArgOnly <String >('output' ,
16581673 resourceProvider.pathContext.join ('doc' , 'api' ), resourceProvider,
1659- isDir : true , help: 'Path to output directory.' ),
1674+ optionIs : OptionKind .dir , help: 'Path to output directory.' ),
16601675 DartdocOptionSyntheticOnly <PackageMeta >(
16611676 'packageMeta' ,
16621677 (DartdocSyntheticOption <PackageMeta > option, Folder dir) {
@@ -1691,7 +1706,9 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
16911706 }
16921707 return packageMetaProvider.defaultSdkDir.path;
16931708 }, packageMetaProvider.resourceProvider,
1694- help: 'Path to the SDK directory.' , isDir: true , mustExist: true ),
1709+ help: 'Path to the SDK directory.' ,
1710+ optionIs: OptionKind .dir,
1711+ mustExist: true ),
16951712 DartdocOptionArgFile <bool >(
16961713 'showUndocumentedCategories' , false , resourceProvider,
16971714 help: "Label categories that aren't documented" , negatable: true ),
0 commit comments