Skip to content

Add Flags class.#12268

Merged
tvolkert merged 2 commits intoflutter:masterfrom
tvolkert:bundle
Sep 28, 2017
Merged

Add Flags class.#12268
tvolkert merged 2 commits intoflutter:masterfrom
tvolkert:bundle

Conversation

@tvolkert
Copy link
Contributor

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.

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.
Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some nitpicking.


Flags get flags => context?.getVariable(Flags) ?? const _EmptyFlags();

class Flags {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we don't use {} for single-line if blocks.


import 'context.dart';

Flags get flags => context?.getVariable(Flags) ?? const _EmptyFlags();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs


dynamic operator [](String key) {
final ArgResults commandResults = _globalResults.command;
if (commandResults?.options?.contains(key) ?? false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ?? false does work, but I think it's less readable than:

final options = commandResults?.options;
if (options != null && options.contains(key)) {
  ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If commandResults.options can be null, why can't _globalResults.options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since none of the conditional code is > 1 LoC, kill the curly brackets.

}

final ArgResults _globalResults;

Copy link
Member

@cbracken cbracken Sep 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cbracken
Copy link
Member

lgtm
However,
lacks docs

I've been dying for a chance to use that, sorry.

@tvolkert tvolkert merged commit 9ea1ff1 into flutter:master Sep 28, 2017
@tvolkert tvolkert deleted the bundle branch September 28, 2017 16:36
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 14, 2019
engine-flutter-autoroll added a commit that referenced this pull request Sep 14, 2019
[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
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
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
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants