devices.dart 1.27 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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 '../base/utils.dart';
9
import '../device.dart';
10
import '../doctor.dart';
11
import '../globals.dart';
12
import '../runner/flutter_command.dart';
13

14
class DevicesCommand extends FlutterCommand {
15
  @override
16
  final String name = 'devices';
17 18

  @override
19
  final String description = 'List all connected devices.';
20 21

  @override
22
  Future<Null> runCommand() async {
23
    if (!doctor.canListAnything) {
24 25 26 27
      throwToolExit(
        "Unable to locate a development device; please run 'flutter doctor' for "
        "information about installing additional components.",
        exitCode: 1);
28 29
    }

30
    List<Device> devices = await deviceManager.getAllConnectedDevices();
31

32
    if (devices.isEmpty) {
33 34 35 36
      printStatus(
        'No devices detected.\n\n'
        'If you expected your device to be detected, please run "flutter doctor" to diagnose\n'
        'potential issues, or visit https://flutter.io/setup/ for troubleshooting tips.');
37
    } else {
38
      printStatus('${devices.length} connected ${pluralize('device', devices.length)}:\n');
Devon Carew's avatar
Devon Carew committed
39
      Device.printDevices(devices);
40
    }
41 42
  }
}