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/utils.dart';
8
import '../device.dart';
9
import '../globals.dart';
10
import '../runner/flutter_command.dart';
11

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

  @override
17
  final String description = 'List all connected devices.';
18 19

  @override
20 21
  bool get requiresProjectRoot => false;

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

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 43 44
    return 0;
  }
}