doctor.dart 1.96 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import '../android/android_workflow.dart';
6
import '../base/common.dart';
7
import '../globals.dart' as globals;
8 9 10
import '../runner/flutter_command.dart';

class DoctorCommand extends FlutterCommand {
11
  DoctorCommand({this.verbose = false}) {
12
    argParser.addFlag('android-licenses',
13
      negatable: false,
14
      help: "Run the Android SDK manager tool to accept the SDK's licenses.",
15
    );
16 17 18 19 20
    argParser.addOption('check-for-remote-artifacts',
      hide: !verbose,
      help: 'Used to determine if Flutter engine artifacts for all platforms '
            'are available for download.',
      valueHelp: 'engine revision git hash',);
21 22
  }

23 24
  final bool verbose;

25
  @override
26
  final String name = 'doctor';
27 28

  @override
29
  final String description = 'Show information about the installed tooling.';
30

31 32 33
  @override
  final String category = FlutterCommandCategory.sdk;

34
  @override
35
  Future<FlutterCommandResult> runCommand() async {
36
    if (argResults?.wasParsed('check-for-remote-artifacts') ?? false) {
37
      final String engineRevision = stringArg('check-for-remote-artifacts')!;
38
      if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
39 40
        final bool success = await globals.doctor?.checkRemoteArtifacts(engineRevision) ?? false;
        if (success) {
41 42 43 44 45 46 47 48
          throwToolExit('Artifacts for engine $engineRevision are missing or are '
              'not yet available.', exitCode: 1);
        }
      } else {
        throwToolExit('Remote artifact revision $engineRevision is not a valid '
            'git hash.');
      }
    }
49
    final bool success = await globals.doctor?.diagnose(
50
      androidLicenses: boolArg('android-licenses'),
51 52
      verbose: verbose,
      androidLicenseValidator: androidLicenseValidator,
53
    ) ?? false;
54
    return FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning);
55 56
  }
}