@@ -433,6 +433,17 @@ class _YamlFileData {
433
433
_YamlFileData (this .data, this .canonicalDirectoryPath);
434
434
}
435
435
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
+
436
447
/// Some DartdocOption subclasses need to keep track of where they
437
448
/// got the value from; this class contains those intermediate results
438
449
/// so that error messages can be more useful.
@@ -503,10 +514,15 @@ abstract class DartdocOption<T> {
503
514
final String name;
504
515
505
516
/// Set to true if this option represents the name of a directory.
506
- final bool isDir;
517
+ bool get isDir => optionIs == OptionKind .dir ;
507
518
508
519
/// 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;
510
526
511
527
/// Set to true if DartdocOption subclasses should validate that the
512
528
/// directory or file exists. Does not imply validation of [defaultsTo] ,
@@ -515,11 +531,13 @@ abstract class DartdocOption<T> {
515
531
516
532
final ResourceProvider resourceProvider;
517
533
518
- DartdocOption (this .name, this .defaultsTo, this .help, this .isDir, this .isFile ,
534
+ DartdocOption (this .name, this .defaultsTo, this .help, this .optionIs ,
519
535
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
+ }
522
539
if (mustExist) {
540
+ // Globs by definition don't have to exist.
523
541
assert (isDir || isFile);
524
542
}
525
543
}
@@ -604,7 +622,7 @@ abstract class DartdocOption<T> {
604
622
/// For a [List<String>] or [String] value, if [isDir] or [isFile] is set,
605
623
/// resolve paths in value relative to canonicalPath.
606
624
T _handlePathsInContext (_OptionValueWithContext <Object > valueWithContext) {
607
- if (valueWithContext? .value == null || ! (isDir || isFile)) {
625
+ if (valueWithContext? .value == null || ! (isDir || isFile || isGlob )) {
608
626
return valueWithContext? .value;
609
627
}
610
628
_validatePaths (valueWithContext);
@@ -715,11 +733,10 @@ class DartdocOptionFileSynth<T> extends DartdocOption<T>
715
733
String name, this ._compute, ResourceProvider resourceprovider,
716
734
{bool mustExist = false ,
717
735
String help = '' ,
718
- bool isDir = false ,
719
- bool isFile = false ,
736
+ OptionKind optionIs = OptionKind .other,
720
737
bool parentDirOverridesChild,
721
738
ConvertYamlToType <T > convertYamlToType})
722
- : super (name, null , help, isDir, isFile , mustExist, convertYamlToType,
739
+ : super (name, null , help, optionIs , mustExist, convertYamlToType,
723
740
resourceprovider) {
724
741
_parentDirOverridesChild = parentDirOverridesChild;
725
742
}
@@ -765,12 +782,10 @@ class DartdocOptionArgSynth<T> extends DartdocOption<T>
765
782
bool mustExist = false ,
766
783
String help = '' ,
767
784
bool hide = false ,
768
- bool isDir = false ,
769
- bool isFile = false ,
785
+ OptionKind optionIs = OptionKind .other,
770
786
bool negatable = false ,
771
787
bool splitCommas})
772
- : super (name, null , help, isDir, isFile, mustExist, null ,
773
- resourceProvider) {
788
+ : super (name, null , help, optionIs, mustExist, null , resourceProvider) {
774
789
_hide = hide;
775
790
_negatable = negatable;
776
791
_splitCommas = splitCommas;
@@ -818,10 +833,8 @@ class DartdocOptionSyntheticOnly<T> extends DartdocOption<T>
818
833
String name, this ._compute, ResourceProvider resourceProvider,
819
834
{bool mustExist = false ,
820
835
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);
825
838
}
826
839
827
840
abstract class DartdocSyntheticOption <T > implements DartdocOption <T > {
@@ -856,7 +869,8 @@ typedef OptionGenerator = Future<List<DartdocOption<Object>>> Function(
856
869
/// option itself.
857
870
class DartdocOptionSet extends DartdocOption <void > {
858
871
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);
860
874
861
875
/// Asynchronous factory that is the main entry point to initialize Dartdoc
862
876
/// options for use.
@@ -908,11 +922,10 @@ class DartdocOptionArgOnly<T> extends DartdocOption<T>
908
922
bool mustExist = false ,
909
923
String help = '' ,
910
924
bool hide = false ,
911
- bool isDir = false ,
912
- bool isFile = false ,
925
+ OptionKind optionIs = OptionKind .other,
913
926
bool negatable = false ,
914
927
bool splitCommas})
915
- : super (name, defaultsTo, help, isDir, isFile , mustExist, null ,
928
+ : super (name, defaultsTo, help, optionIs , mustExist, null ,
916
929
resourceProvider) {
917
930
_hide = hide;
918
931
_negatable = negatable;
@@ -949,12 +962,11 @@ class DartdocOptionArgFile<T> extends DartdocOption<T>
949
962
bool mustExist = false ,
950
963
String help = '' ,
951
964
bool hide = false ,
952
- bool isDir = false ,
953
- bool isFile = false ,
965
+ OptionKind optionIs = OptionKind .other,
954
966
bool negatable = false ,
955
967
bool parentDirOverridesChild = false ,
956
968
bool splitCommas})
957
- : super (name, defaultsTo, help, isDir, isFile , mustExist, null ,
969
+ : super (name, defaultsTo, help, optionIs , mustExist, null ,
958
970
resourceProvider) {
959
971
_abbr = abbr;
960
972
_hide = hide;
@@ -1007,12 +1019,11 @@ class DartdocOptionFileOnly<T> extends DartdocOption<T>
1007
1019
String name, T defaultsTo, ResourceProvider resourceProvider,
1008
1020
{bool mustExist = false ,
1009
1021
String help = '' ,
1010
- bool isDir = false ,
1011
- bool isFile = false ,
1022
+ OptionKind optionIs = OptionKind .other,
1012
1023
bool parentDirOverridesChild = false ,
1013
1024
ConvertYamlToType <T > convertYamlToType})
1014
- : super (name, defaultsTo, help, isDir, isFile, mustExist ,
1015
- convertYamlToType, resourceProvider) {
1025
+ : super (name, defaultsTo, help, optionIs, mustExist, convertYamlToType ,
1026
+ resourceProvider) {
1016
1027
_parentDirOverridesChild = parentDirOverridesChild;
1017
1028
}
1018
1029
@@ -1260,8 +1271,10 @@ abstract class _DartdocArgOption<T> implements DartdocOption<T> {
1260
1271
1261
1272
T retval;
1262
1273
// 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.
1265
1278
if (_isBool || _isListString || _isString) {
1266
1279
retval = _argResults[argName];
1267
1280
} else if (_isInt) {
@@ -1566,7 +1579,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1566
1579
}, resourceProvider,
1567
1580
help: 'Remove text from libraries with the following names.' ),
1568
1581
DartdocOptionArgFile <String >('examplePathPrefix' , null , resourceProvider,
1569
- isDir : true ,
1582
+ optionIs : OptionKind .dir ,
1570
1583
help: 'Prefix for @example paths.\n (defaults to the project root)' ,
1571
1584
mustExist: true ),
1572
1585
DartdocOptionArgFile <List <String >>('exclude' , [], resourceProvider,
@@ -1580,7 +1593,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1580
1593
(DartdocSyntheticOption <String > option, Folder dir) =>
1581
1594
resolveTildePath (Platform .environment['FLUTTER_ROOT' ]),
1582
1595
resourceProvider,
1583
- isDir : true ,
1596
+ optionIs : OptionKind .dir ,
1584
1597
help: 'Root of the Flutter SDK, specified from environment.' ,
1585
1598
mustExist: true ),
1586
1599
DartdocOptionArgOnly <bool >('hideSdkText' , false , resourceProvider,
@@ -1592,7 +1605,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1592
1605
help: 'Library names to generate docs for.' , splitCommas: true ),
1593
1606
DartdocOptionArgFile <List <String >>(
1594
1607
'includeExternal' , null , resourceProvider,
1595
- isFile : true ,
1608
+ optionIs : OptionKind .file ,
1596
1609
help:
1597
1610
'Additional (external) dart files to include; use "dir/fileName", '
1598
1611
'as in lib/material.dart.' ,
@@ -1605,7 +1618,9 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1605
1618
'HTML into dartdoc output.' ),
1606
1619
DartdocOptionArgOnly <String >(
1607
1620
'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 ),
1609
1624
DartdocOptionSyntheticOnly <String >('inputDir' ,
1610
1625
(DartdocSyntheticOption <String > option, Folder dir) {
1611
1626
if (option.parent['sdkDocs' ].valueAt (dir)) {
@@ -1614,7 +1629,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1614
1629
return option.parent['input' ].valueAt (dir);
1615
1630
}, resourceProvider,
1616
1631
help: 'Path to source directory (with override if --sdk-docs)' ,
1617
- isDir : true ,
1632
+ optionIs : OptionKind .dir ,
1618
1633
mustExist: true ),
1619
1634
DartdocOptionSet ('linkTo' , resourceProvider)
1620
1635
..addAll ([
@@ -1656,7 +1671,7 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1656
1671
]),
1657
1672
DartdocOptionArgOnly <String >('output' ,
1658
1673
resourceProvider.pathContext.join ('doc' , 'api' ), resourceProvider,
1659
- isDir : true , help: 'Path to output directory.' ),
1674
+ optionIs : OptionKind .dir , help: 'Path to output directory.' ),
1660
1675
DartdocOptionSyntheticOnly <PackageMeta >(
1661
1676
'packageMeta' ,
1662
1677
(DartdocSyntheticOption <PackageMeta > option, Folder dir) {
@@ -1691,7 +1706,9 @@ Future<List<DartdocOption<Object>>> createDartdocOptions(
1691
1706
}
1692
1707
return packageMetaProvider.defaultSdkDir.path;
1693
1708
}, 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 ),
1695
1712
DartdocOptionArgFile <bool >(
1696
1713
'showUndocumentedCategories' , false , resourceProvider,
1697
1714
help: "Label categories that aren't documented" , negatable: true ),
0 commit comments