-
Notifications
You must be signed in to change notification settings - Fork 125
Implement new combined dartdoc option class #1666
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Substantially, 👍.
A few nits and style conversation starters...
import 'package:path/path.dart' as pathLib; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
import 'logging.dart'; | ||
|
||
/// Constants to help with type checking, because T is int and so forth | ||
/// don't work in Dart. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/src/dartdoc_options.dart
Outdated
const double _kDoubleVal = 0.0; | ||
const bool _kBoolVal = true; | ||
|
||
class DartdocOptionError extends DartDocFailure { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be more consistent to have them both named Dartdoc* or DartDoc*?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed all names to DartdocThing.
|
||
// The choice not to use reflection means there's some ugly type checking, | ||
// somewhat more ugly than we'd have to do anyway to automatically convert | ||
// command line arguments and yaml data to real types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
} | ||
|
||
/// A [DartdocOption] that only contains other [DartdocOption]s and is not an option itself. | ||
class DartdocOptionSet extends DartdocOption<Null> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this makes me think the name DartDoc was a typo (meaning Dartdoc instead).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Between Dartdoc and DartDoc I prefer Dartdoc, because the command is a single word in my mind. So I've switched them to Dartdoc -- I think it's really a matter of personal preference. I'm interested in consistency though so I've changed them all.
lib/src/dartdoc_options.dart
Outdated
dartdocYaml = pathLib.canonicalize(pathLib.join( | ||
valueWithContext.canonicalDirectoryPath, | ||
valueWithContext.definingFile)); | ||
description = "Field ${fieldName} from ${dartdocYaml}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> single quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I keep doing this because in bash single quotes mean no resolution of expressions like '${foo}'. I'll try to reprogram myself differently. Fixed.
|
||
dartdocOptionSetArgs = new DartdocOptionSet('dartdoc'); | ||
dartdocOptionSetArgs | ||
.add(new DartdocOptionArgOnly<bool>('cauliflowerSystem', false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me smile. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-)
dartdocOptionSetBoth.parseArguments(['--my-special-integer', '14']); | ||
expect( | ||
dartdocOptionSetBoth['mySpecialInteger'].valueAt(secondDirFirstSub), | ||
equals(14)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's just a style thing but I prefer to elide explicit calls to equals since I think it defaults to that matcher. In other words, you can just say 14
. Totally up to you though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general dartdoc style is to be explicit in tests, so I've continued that here.
test('validate arg defaults do not override file', () { | ||
dartdocOptionSetBoth.parseArguments([]); | ||
expect(dartdocOptionSetBoth['mySpecialInteger'].valueAt(secondDir), | ||
equals(11)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here and below obviously....
() { | ||
dartdocOptionSetBoth.parseArguments(['--my-special-integer', '91']); | ||
expect(dartdocOptionSetBoth['mySpecialInteger'].valueAt(secondDir), | ||
equals(91)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, maybe it actually reads better to be explicit?
test/dartdoc_options_test.dart
Outdated
expect( | ||
dartdocOptionSetArgs['warn']['unrecognizedVegetable'] | ||
.valueAt(tempDir), | ||
equals(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> isFalse
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
A new class, "DartdocOption", and its subclasses are intended to replace the existing DartDocConfig and DartdocOptions classes. This class automatically handles arguments that can override configuration file options, check for the existence of files, and print useful error messages. It condenses some of the ugly things one typically has to do to make a config object work, so that you can declare them like this:
This will read a dartdoc_options.yaml file like this:
and command line options like this:
overriding the file with the command line options and throwing an assert if files declared that must exist don't, when accessing via:
The valueAt allows dartdoc to compute this value for different combinations of config files and arguments, and it should be sufficiently cached to minimize performance hits.
This PR does not actually use this anywhere besides the tests, that's for a followup.