
This attempts to re-land #22656. There are two changes from the original: I turned off wrapping completely when not sending output to a terminal. Previously I had defaulted to wrapping at and arbitrary 100 chars in that case, just to keep long messages from being too long, but that turns out the be a bad idea because there are tests that are relying on the specific form of the output. It's also pretty arbitrary, and mostly people sending output to a non-terminal will want unwrapped text. I found a better way to terminate ANSI color/bold sequences, so that they can be embedded within each other without needed quite as complex a dance with removing redundant sequences. As part of these changes, I removed the Logger.supportsColor setter so that the one source of truth for color support is in AnsiTerminal.supportsColor. * Turn on line wrapping again in usage and status messages, adds ANSI color to doctor and analysis messages. (#22656) This turns on text wrapping for usage messages and status messages. When on a terminal, wraps to the width of the terminal. When writing to a non-terminal, wrap lines at a default column width (currently defined to be 100 chars). If --no-wrap is specified, then no wrapping occurs. If --wrap-column is specified, wraps to that column (if --wrap is on). Adds ANSI color to the doctor and analysis output on terminals. This is in this PR with the wrapping, since wrapping needs to know how to count visible characters in the presence of ANSI sequences. (This is just one more step towards re-implementing all of Curses for Flutter. :-)) Will not print ANSI sequences when sent to a non-terminal, or of --no-color is specified. Fixes ANSI color and bold sequences so that they can be combined (bold, colored text), and a small bug in indentation calculation for wrapping. Since wrapping is now turned on, also removed many redundant '\n's in the code.
152 lines
4.1 KiB
Dart
152 lines
4.1 KiB
Dart
// Copyright 2016 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/os.dart';
|
|
import '../dart/pub.dart';
|
|
import '../project.dart';
|
|
import '../runner/flutter_command.dart';
|
|
|
|
class PackagesCommand extends FlutterCommand {
|
|
PackagesCommand() {
|
|
addSubcommand(PackagesGetCommand('get', false));
|
|
addSubcommand(PackagesGetCommand('upgrade', true));
|
|
addSubcommand(PackagesTestCommand());
|
|
addSubcommand(PackagesPassthroughCommand());
|
|
}
|
|
|
|
@override
|
|
final String name = 'packages';
|
|
|
|
@override
|
|
List<String> get aliases => const <String>['pub'];
|
|
|
|
@override
|
|
final String description = 'Commands for managing Flutter packages.';
|
|
|
|
@override
|
|
Future<FlutterCommandResult> runCommand() async => null;
|
|
}
|
|
|
|
class PackagesGetCommand extends FlutterCommand {
|
|
PackagesGetCommand(this.name, this.upgrade) {
|
|
requiresPubspecYaml();
|
|
argParser.addFlag('offline',
|
|
negatable: false,
|
|
help: 'Use cached packages instead of accessing the network.'
|
|
);
|
|
}
|
|
|
|
@override
|
|
final String name;
|
|
|
|
final bool upgrade;
|
|
|
|
@override
|
|
String get description {
|
|
return '${ upgrade ? "Upgrade" : "Get" } packages in a Flutter project.';
|
|
}
|
|
|
|
@override
|
|
String get invocation {
|
|
return '${runner.executableName} packages $name [<target directory>]';
|
|
}
|
|
|
|
Future<void> _runPubGet (String directory) async {
|
|
await pubGet(context: PubContext.pubGet,
|
|
directory: directory,
|
|
upgrade: upgrade ,
|
|
offline: argResults['offline'],
|
|
checkLastModified: false,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<FlutterCommandResult> runCommand() async {
|
|
if (argResults.rest.length > 1)
|
|
throwToolExit('Too many arguments.\n$usage');
|
|
|
|
final String target = findProjectRoot(
|
|
argResults.rest.length == 1 ? argResults.rest[0] : null
|
|
);
|
|
if (target == null) {
|
|
throwToolExit(
|
|
'Expected to find project root in '
|
|
'${ argResults.rest.length == 1 ? argResults.rest[0] : "current working directory" }.'
|
|
);
|
|
}
|
|
|
|
await _runPubGet(target);
|
|
final FlutterProject rootProject = await FlutterProject.fromPath(target);
|
|
await rootProject.ensureReadyForPlatformSpecificTooling();
|
|
|
|
// Get/upgrade packages in example app as well
|
|
if (rootProject.hasExampleApp) {
|
|
final FlutterProject exampleProject = rootProject.example;
|
|
await _runPubGet(exampleProject.directory.path);
|
|
await exampleProject.ensureReadyForPlatformSpecificTooling();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
class PackagesTestCommand extends FlutterCommand {
|
|
PackagesTestCommand() {
|
|
requiresPubspecYaml();
|
|
}
|
|
|
|
@override
|
|
String get name => 'test';
|
|
|
|
@override
|
|
String get description {
|
|
return 'Run the "test" package.\n'
|
|
'This is similar to "flutter test", but instead of hosting the tests in the '
|
|
'flutter environment it hosts the tests in a pure Dart environment. The main '
|
|
'differences are that the "dart:ui" library is not available and that tests '
|
|
'run faster. This is helpful for testing libraries that do not depend on any '
|
|
'packages from the Flutter SDK. It is equivalent to "pub run test".';
|
|
}
|
|
|
|
@override
|
|
String get invocation {
|
|
return '${runner.executableName} packages test [<tests...>]';
|
|
}
|
|
|
|
@override
|
|
Future<FlutterCommandResult> runCommand() async {
|
|
await pub(<String>['run', 'test']..addAll(argResults.rest), context: PubContext.runTest, retry: false);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
class PackagesPassthroughCommand extends FlutterCommand {
|
|
PackagesPassthroughCommand() {
|
|
requiresPubspecYaml();
|
|
}
|
|
|
|
@override
|
|
String get name => 'pub';
|
|
|
|
@override
|
|
String get description {
|
|
return 'Pass the remaining arguments to Dart\'s "pub" tool.\n'
|
|
'This runs the "pub" tool in a Flutter context.';
|
|
}
|
|
|
|
@override
|
|
String get invocation {
|
|
return '${runner.executableName} packages pub [<arguments...>]';
|
|
}
|
|
|
|
@override
|
|
Future<FlutterCommandResult> runCommand() async {
|
|
await pubInteractively(argResults.rest);
|
|
return null;
|
|
}
|
|
}
|