1// Copyright 2016 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import 'dart:async'; 6 7import '../base/common.dart'; 8import '../doctor.dart'; 9import '../runner/flutter_command.dart'; 10 11class DoctorCommand extends FlutterCommand { 12 DoctorCommand({this.verbose = false}) { 13 argParser.addFlag('android-licenses', 14 defaultsTo: false, 15 negatable: false, 16 help: 'Run the Android SDK manager tool to accept the SDK\'s licenses.', 17 ); 18 argParser.addOption('check-for-remote-artifacts', 19 hide: !verbose, 20 help: 'Used to determine if Flutter engine artifacts for all platforms ' 21 'are available for download.', 22 valueHelp: 'engine revision git hash',); 23 } 24 25 final bool verbose; 26 27 @override 28 final String name = 'doctor'; 29 30 @override 31 final String description = 'Show information about the installed tooling.'; 32 33 @override 34 Future<Set<DevelopmentArtifact>> get requiredArtifacts async { 35 return <DevelopmentArtifact>{ 36 DevelopmentArtifact.universal, 37 // This is required because we use gen_snapshot to check if the host 38 // machine can execute the provided artifacts. See `_genSnapshotRuns` 39 // in `doctor.dart`. 40 DevelopmentArtifact.android, 41 }; 42 } 43 44 @override 45 Future<FlutterCommandResult> runCommand() async { 46 if (argResults.wasParsed('check-for-remote-artifacts')) { 47 final String engineRevision = argResults['check-for-remote-artifacts']; 48 if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) { 49 final bool success = await doctor.checkRemoteArtifacts(engineRevision); 50 if (!success) { 51 throwToolExit('Artifacts for engine $engineRevision are missing or are ' 52 'not yet available.', exitCode: 1); 53 } 54 } else { 55 throwToolExit('Remote artifact revision $engineRevision is not a valid ' 56 'git hash.'); 57 } 58 } 59 final bool success = await doctor.diagnose(androidLicenses: argResults['android-licenses'], verbose: verbose); 60 return FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning); 61 } 62} 63