44
55import '../android/android_workflow.dart' ;
66import '../base/common.dart' ;
7+ import '../context/tool_context.dart' ;
8+ import '../doctor.dart' ;
79import '../globals.dart' as globals;
810import '../runner/flutter_command.dart' ;
911
1012class 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