update_packages.dart 1.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// 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';
import 'dart:io';

import '../dart/pub.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';

class UpdatePackagesCommand extends FlutterCommand {
13
  UpdatePackagesCommand({ this.hidden: false }) {
14 15 16 17 18 19 20
    argParser.addFlag(
      'upgrade',
      help: 'Run "pub upgrade" rather than "pub get".',
      defaultsTo: false
    );
  }

21
  @override
22
  final String name = 'update-packages';
23 24

  @override
25 26
  final String description = 'Update the packages inside the Flutter repo.';

27
  @override
28
  final bool hidden;
29

30
  @override
31 32 33 34
  bool get requiresProjectRoot => false;

  @override
  Future<int> runInProject() async {
35 36 37 38 39
    try {
      Stopwatch timer = new Stopwatch()..start();
      int count = 0;
      bool upgrade = argResults['upgrade'];

40 41 42 43 44 45
      for (Directory dir in runner.getRepoPackages()) {
        int code = await pubGet(directory: dir.path, upgrade: upgrade, checkLastModified: false);
        if (code != 0)
          throw code;
        count++;
      }
46

47 48
      double seconds = timer.elapsedMilliseconds / 1000.0;
      printStatus('\nRan \'pub\' $count time${count == 1 ? "" : "s"} in ${seconds.toStringAsFixed(1)}s.');
49 50 51 52 53

      return 0;
    } on int catch (code) {
      return code;
    }
54 55
  }
}