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

import 'dart:async';

7
import '../base/common.dart';
8
import '../doctor.dart';
9 10 11
import '../runner/flutter_command.dart';

class DoctorCommand extends FlutterCommand {
12
  DoctorCommand({this.verbose = false}) {
13 14
    argParser.addFlag('android-licenses',
      defaultsTo: false,
15
      negatable: false,
16
      help: "Run the Android SDK manager tool to accept the SDK's licenses.",
17
    );
18 19 20 21 22
    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',);
23 24
  }

25 26
  final bool verbose;

27
  @override
28
  final String name = 'doctor';
29 30

  @override
31
  final String description = 'Show information about the installed tooling.';
32

33 34 35 36 37 38
  @override
  Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
    return <DevelopmentArtifact>{
      // This is required because we use gen_snapshot to check if the host
      // machine can execute the provided artifacts. See `_genSnapshotRuns`
      // in `doctor.dart`.
39
      DevelopmentArtifact.androidGenSnapshot,
40 41 42
    };
  }

43
  @override
44
  Future<FlutterCommandResult> runCommand() async {
45
    if (argResults.wasParsed('check-for-remote-artifacts')) {
46
      final String engineRevision = stringArg('check-for-remote-artifacts');
47 48 49 50 51 52 53 54 55 56 57
      if (engineRevision.startsWith(RegExp(r'[a-f0-9]{1,40}'))) {
        final bool success = await doctor.checkRemoteArtifacts(engineRevision);
        if (!success) {
          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.');
      }
    }
58
    final bool success = await doctor.diagnose(androidLicenses: boolArg('android-licenses'), verbose: verbose);
59
    return FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning);
60 61
  }
}