Visitar URL original
[tool] Migrate DoctorCommand to modular dependency injection · flutter/flutter@6ec14e5 · GitHub
Skip to content

Commit 6ec14e5

Browse files
committed
[tool] Migrate DoctorCommand to modular dependency injection
1 parent e28b446 commit 6ec14e5

3 files changed

Lines changed: 387 additions & 351 deletions

File tree

‎packages/flutter_tools/lib/executable.dart‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'runner.dart' as runner;
6+
import 'src/android/android_workflow.dart';
67
import 'src/base/context.dart';
78
import 'src/base/io.dart';
89
import 'src/base/logger.dart';
@@ -245,7 +246,12 @@ List<FlutterCommand> generateCommands({
245246
DaemonCommand(hidden: !verboseHelp),
246247
DebugAdapterCommand(verboseHelp: verboseHelp),
247248
DevicesCommand(verboseHelp: verboseHelp),
248-
DoctorCommand(verbose: verbose),
249+
DoctorCommand(
250+
verbose: verbose,
251+
toolContext: toolDependencies.toolContext,
252+
doctor: globals.doctor,
253+
androidLicenseValidator: androidLicenseValidator,
254+
),
249255
DowngradeCommand(verboseHelp: verboseHelp, logger: toolDependencies.toolContext.logger),
250256
DriveCommand(
251257
verboseHelp: verboseHelp,

‎packages/flutter_tools/lib/src/commands/doctor.dart‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
import '../android/android_workflow.dart';
66
import '../base/common.dart';
7-
import '../globals.dart' as globals;
7+
import '../context/tool_context.dart';
8+
import '../doctor.dart';
89
import '../runner/flutter_command.dart';
910

1011
class DoctorCommand extends FlutterCommand {
11-
DoctorCommand({this.verbose = false}) {
12+
DoctorCommand({
13+
required ToolContext toolContext,
14+
Doctor? doctor,
15+
AndroidLicenseValidator? androidLicenseValidator,
16+
this.verbose = false,
17+
}) : _doctor = doctor,
18+
_androidLicenseValidator = androidLicenseValidator,
19+
super(toolContext: toolContext) {
1220
argParser.addFlag(
1321
'android-licenses',
1422
negatable: false,
@@ -24,6 +32,8 @@ class DoctorCommand extends FlutterCommand {
2432
);
2533
}
2634

35+
final Doctor? _doctor;
36+
final AndroidLicenseValidator? _androidLicenseValidator;
2737
final bool verbose;
2838

2939
@override
@@ -37,10 +47,13 @@ class DoctorCommand extends FlutterCommand {
3747

3848
@override
3949
Future<FlutterCommandResult> runCommand() async {
50+
final Doctor? doctor = _doctor;
51+
final AndroidLicenseValidator? androidLicenseValidator = _androidLicenseValidator;
52+
4053
if (argResults?.wasParsed('check-for-remote-artifacts') ?? false) {
4154
final String engineRevision = stringArg('check-for-remote-artifacts')!;
4255
if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
43-
final bool success = await globals.doctor?.checkRemoteArtifacts(engineRevision) ?? false;
56+
final bool success = await doctor?.checkRemoteArtifacts(engineRevision) ?? false;
4457
if (success) {
4558
throwToolExit(
4659
'Artifacts for engine $engineRevision are missing or are '
@@ -56,7 +69,7 @@ class DoctorCommand extends FlutterCommand {
5669
}
5770
}
5871
final bool success =
59-
await globals.doctor?.diagnose(
72+
await doctor?.diagnose(
6073
androidLicenses: boolArg('android-licenses'),
6174
verbose: verbose,
6275
androidLicenseValidator: androidLicenseValidator,

0 commit comments

Comments
 (0)