Add Flags class.#12268
Conversation
This class lives in the Context and allows callers to "inject" flag values, where flag values are first extracted from the command arguments, then from the global arguments as a fallback.
yjbanov
left a comment
There was a problem hiding this comment.
LGTM with some nitpicking.
|
|
||
| Flags get flags => context?.getVariable(Flags) ?? const _EmptyFlags(); | ||
|
|
||
| class Flags { |
There was a problem hiding this comment.
Docs explaining the existence of this class would be great.
|
|
||
| dynamic operator [](String key) { | ||
| final ArgResults commandResults = _globalResults.command; | ||
| if (commandResults?.options?.contains(key) ?? false) { |
There was a problem hiding this comment.
nit: we don't use {} for single-line if blocks.
|
|
||
| import 'context.dart'; | ||
|
|
||
| Flags get flags => context?.getVariable(Flags) ?? const _EmptyFlags(); |
|
|
||
| dynamic operator [](String key) { | ||
| final ArgResults commandResults = _globalResults.command; | ||
| if (commandResults?.options?.contains(key) ?? false) { |
There was a problem hiding this comment.
nit: ?? false does work, but I think it's less readable than:
final options = commandResults?.options;
if (options != null && options.contains(key)) {
...
There was a problem hiding this comment.
+1 in both agreement and nitpickiness. ;-)
| final ArgResults commandResults = _globalResults.command; | ||
| if (commandResults?.options?.contains(key) ?? false) { | ||
| return commandResults[key]; | ||
| } else if (_globalResults.options.contains(key)) { |
There was a problem hiding this comment.
If commandResults.options can be null, why can't _globalResults.options?
There was a problem hiding this comment.
commandResults.options can't be null, but commandResults can be null, which can make commandResults?.options null, which necessitates the second ?.
| return commandResults[key]; | ||
| } else if (_globalResults.options.contains(key)) { | ||
| return _globalResults[key]; | ||
| } |
There was a problem hiding this comment.
Since none of the conditional code is > 1 LoC, kill the curly brackets.
| } | ||
|
|
||
| final ArgResults _globalResults; | ||
|
|
There was a problem hiding this comment.
Worth adding a bool contains(String key)? Given that null isn't a valid value, it's probably fine as is; just thinking of consistency with package:args.
[email protected]:flutter/engine.git/compare/e12decfdd210...fdb7bbf git log e12decf..fdb7bbf --no-merges --oneline 2019-09-13 [email protected] Revert "Close the tree (#12268)" (flutter/engine#12272) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
flutter#40469) [email protected]:flutter/engine.git/compare/e12decfdd210...fdb7bbf git log e12decf..fdb7bbf --no-merges --oneline 2019-09-13 [email protected] Revert "Close the tree (flutter#12268)" (flutter/engine#12272) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md


This class lives in the Context and allows callers to "inject"
flag values, where flag values are first extracted from the
command arguments, then from the global arguments as a fallback.