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

Commit 0c75d37

Browse files
committed
[tool] Migrate DoctorCommand to modular dependency injection
1 parent d2a79cc commit 0c75d37

4 files changed

Lines changed: 388 additions & 354 deletions

File tree

‎packages/flutter_tools/lib/executable.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ List<FlutterCommand> generateCommands({
245245
DaemonCommand(hidden: !verboseHelp),
246246
DebugAdapterCommand(verboseHelp: verboseHelp),
247247
DevicesCommand(verboseHelp: verboseHelp),
248-
DoctorCommand(verbose: verbose),
248+
DoctorCommand(verbose: verbose, toolContext: toolDependencies.toolContext),
249249
DowngradeCommand(verboseHelp: verboseHelp, logger: toolDependencies.toolContext.logger),
250250
DriveCommand(
251251
verboseHelp: verboseHelp,

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

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

55
import '../android/android_workflow.dart';
66
import '../base/common.dart';
7+
import '../context/tool_context.dart';
8+
import '../doctor.dart';
79
import '../globals.dart' as globals;
810
import '../runner/flutter_command.dart';
911

1012
class DoctorCommand extends FlutterCommand {
11-
DoctorCommand({this.verbose = false}) {
13+
DoctorCommand({
14+
required ToolContext toolContext,
15+
Doctor? doctor,
16+
AndroidLicenseValidator? androidLicenseValidator,
17+
this.verbose = false,
18+
}) : _doctor = doctor,
19+
_androidLicenseValidator = androidLicenseValidator,
20+
super(toolContext: toolContext) {
1221
argParser.addFlag(
1322
'android-licenses',
1423
negatable: false,
@@ -24,8 +33,14 @@ class DoctorCommand extends FlutterCommand {
2433
);
2534
}
2635

36+
final Doctor? _doctor;
37+
final AndroidLicenseValidator? _androidLicenseValidator;
2738
final bool verbose;
2839

40+
Doctor? get _effectiveDoctor => _doctor ?? (toolContext == null ? globals.doctor : null);
41+
AndroidLicenseValidator? get _effectiveAndroidLicenseValidator =>
42+
_androidLicenseValidator ?? (toolContext == null ? androidLicenseValidator : null);
43+
2944
@override
3045
final name = 'doctor';
3146

@@ -37,10 +52,11 @@ class DoctorCommand extends FlutterCommand {
3752

3853
@override
3954
Future<FlutterCommandResult> runCommand() async {
55+
final Doctor? doctor = _effectiveDoctor;
4056
if (argResults?.wasParsed('check-for-remote-artifacts') ?? false) {
4157
final String engineRevision = stringArg('check-for-remote-artifacts')!;
4258
if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
43-
final bool success = await globals.doctor?.checkRemoteArtifacts(engineRevision) ?? false;
59+
final bool success = await doctor?.checkRemoteArtifacts(engineRevision) ?? false;
4460
if (success) {
4561
throwToolExit(
4662
'Artifacts for engine $engineRevision are missing or are '
@@ -56,10 +72,10 @@ class DoctorCommand extends FlutterCommand {
5672
}
5773
}
5874
final bool success =
59-
await globals.doctor?.diagnose(
75+
await doctor?.diagnose(
6076
androidLicenses: boolArg('android-licenses'),
6177
verbose: verbose,
62-
androidLicenseValidator: androidLicenseValidator,
78+
androidLicenseValidator: _effectiveAndroidLicenseValidator,
6379
) ??
6480
false;
6581
return FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning);

0 commit comments

Comments
 (0)