mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Remove the workaround that pinned args to v0.13.6
This reverts most of the changes in commit 6331b6c8b5
* throw exception if exit code is not an integer
* rework command infrastructure to throw ToolExit when non-zero exitCode
* convert commands to return Future<Null>
* cleanup remaining commands to use throwToolExit for non-zero exit code
* remove isUnusual exception message
* add type annotations for updated args package
67 lines
2.0 KiB
Dart
67 lines
2.0 KiB
Dart
// 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 '../base/common.dart';
|
|
import '../base/process.dart';
|
|
import '../cache.dart';
|
|
import '../globals.dart';
|
|
import '../runner/flutter_command.dart';
|
|
|
|
class ChannelCommand extends FlutterCommand {
|
|
@override
|
|
final String name = 'channel';
|
|
|
|
@override
|
|
final String description = 'List or switch flutter channels.';
|
|
|
|
@override
|
|
String get invocation => '${runner.executableName} $name [<channel-name>]';
|
|
|
|
@override
|
|
Future<Null> runCommand() {
|
|
switch (argResults.rest.length) {
|
|
case 0:
|
|
return _listChannels();
|
|
case 1:
|
|
return _switchChannel(argResults.rest[0]);
|
|
default:
|
|
throw new ToolExit('Too many arguments.\n$usage');
|
|
}
|
|
}
|
|
|
|
Future<Null> _listChannels() async {
|
|
String currentBranch = runSync(
|
|
<String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
|
workingDirectory: Cache.flutterRoot);
|
|
|
|
printStatus('Flutter channels:');
|
|
int result = await runCommandAndStreamOutput(
|
|
<String>['git', 'branch', '-r'],
|
|
workingDirectory: Cache.flutterRoot,
|
|
mapFunction: (String line) {
|
|
List<String> split = line.split('/');
|
|
if (split.length < 2) return null;
|
|
String branchName = split[1];
|
|
if (branchName.startsWith('HEAD')) return null;
|
|
if (branchName == currentBranch) return '* $branchName';
|
|
return ' $branchName';
|
|
},
|
|
);
|
|
if (result != 0)
|
|
throwToolExit('List channels failed: $result', exitCode: result);
|
|
}
|
|
|
|
Future<Null> _switchChannel(String branchName) async {
|
|
printStatus('Switching to flutter channel named $branchName');
|
|
int result = await runCommandAndStreamOutput(
|
|
<String>['git', 'checkout', branchName],
|
|
workingDirectory: Cache.flutterRoot,
|
|
);
|
|
if (result != 0)
|
|
throwToolExit('Switch channel failed: $result', exitCode: result);
|
|
}
|
|
}
|