list.dart 1020 Bytes
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/context.dart';
8
import '../device.dart';
9
import '../runner/flutter_command.dart';
10

11 12 13
class ListCommand extends FlutterCommand {
  final String name = 'list';
  final String description = 'List all connected devices.';
14

15 16
  bool get requiresProjectRoot => false;

17
  Future<int> runInProject() async {
18
    DeviceManager deviceManager = new DeviceManager();
19

20
    List<Device> devices = await deviceManager.getDevices();
21

22
    if (devices.isEmpty) {
23
      printStatus('No connected devices.');
24
    } else {
25 26 27
      printStatus('${devices.length} connected ${pluralize('device', devices.length)}:');
      printStatus('');

28
      for (Device device in devices) {
29
        printStatus('${device.name} (${device.id})');
30 31 32
      }
    }

33 34 35
    return 0;
  }
}
36 37

String pluralize(String word, int count) => count == 1 ? word : word + 's';