[flutter_tools] remove zone level overrides of verbose and daemon logging (#57448)

Make it possible for all FlutterCommands to be global free, by moving instantiation to inside the Zone context. Additionally, provide VerboseLogger and NotifyLogger (daemon) at the top level and remove from command-specific overrides.

This allows removing a work around where web devices needed to look up directly from the context in non-test code.

Technically the output preferences are still zone injected, but these will be moved soon as they were not being used correctly by the top level command (the injection comes after ArgParser reads the overflow values, causing numerous wrap issues)
This commit is contained in:
Jonah Williams
2020-06-04 16:35:36 -07:00
committed by GitHub
parent e9a4759947
commit f5de6aadd4
15 changed files with 131 additions and 92 deletions

View File

@@ -4,7 +4,9 @@
import 'dart:async';
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
@@ -78,7 +80,7 @@ String getFlutterRoot() {
}
CommandRunner<void> createTestCommandRunner([ FlutterCommand command ]) {
final FlutterCommandRunner runner = FlutterCommandRunner();
final FlutterCommandRunner runner = TestFlutterCommandRunner();
if (command != null) {
runner.addCommand(command);
}
@@ -352,3 +354,20 @@ class FakeVmServiceStreamResponse implements VmServiceExpectation {
@override
bool get isRequest => false;
}
class TestFlutterCommandRunner extends FlutterCommandRunner {
@override
Future<void> runCommand(ArgResults topLevelResults) async {
final Logger topLevelLogger = globals.logger;
final Map<Type, dynamic> contextOverrides = <Type, dynamic>{
if (topLevelResults['verbose'] as bool)
Logger: VerboseLogger(topLevelLogger),
};
return context.run<void>(
overrides: contextOverrides.map<Type, Generator>((Type type, dynamic value) {
return MapEntry<Type, Generator>(type, () => value);
}),
body: () => super.runCommand(topLevelResults),
);
}
}