[et] Correctly plumb usage line length limit (flutter/engine#52039)

The `Command`s added to a `CommandRunner` don't automatically inherit
the `CommandRunner`'s usage line length limit. This PR does the
necessary plumbing. Help messages look nicer now.
This commit is contained in:
Zachary Anderson
2024-04-11 08:39:05 -07:00
committed by GitHub
parent eef5e09ab4
commit 0b6ce345a3
11 changed files with 83 additions and 9 deletions

View File

@@ -16,6 +16,7 @@ final class BuildCommand extends CommandBase {
required super.environment,
required Map<String, BuilderConfig> configs,
super.verbose = false,
super.usageLineLength,
}) {
builds = runnableBuilds(environment, configs, verbose);
debugCheckBuilds(builds);

View File

@@ -16,13 +16,17 @@ abstract base class CommandBase extends Command<int> {
CommandBase({
required this.environment,
this.verbose = false,
});
int? usageLineLength,
}) : argParser = ArgParser(usageLineLength: usageLineLength);
/// The host system environment.
final Environment environment;
/// Whether verbose logging is enabled.
final bool verbose;
@override
final ArgParser argParser;
}
/// Adds the -c (--config) option to the parser.

View File

@@ -16,7 +16,7 @@ import 'query_command.dart';
import 'run_command.dart';
import 'test_command.dart';
const int _usageLineLength = 80;
const int _usageLineLength = 100;
/// The root command runner.
final class ToolCommandRunner extends CommandRunner<int> {
@@ -28,13 +28,42 @@ final class ToolCommandRunner extends CommandRunner<int> {
this.verbose = false,
}) : super(toolName, toolDescription, usageLineLength: _usageLineLength) {
final List<Command<int>> commands = <Command<int>>[
FetchCommand(environment: environment),
FormatCommand(environment: environment),
QueryCommand(environment: environment, configs: configs, verbose: verbose),
BuildCommand(environment: environment, configs: configs, verbose: verbose),
RunCommand(environment: environment, configs: configs, verbose: verbose),
LintCommand(environment: environment),
TestCommand(environment: environment, configs: configs, verbose: verbose),
FetchCommand(
environment: environment,
usageLineLength: _usageLineLength,
),
FormatCommand(
environment: environment,
usageLineLength: _usageLineLength,
),
QueryCommand(
environment: environment,
configs: configs,
verbose: verbose,
usageLineLength: _usageLineLength,
),
BuildCommand(
environment: environment,
configs: configs,
verbose: verbose,
usageLineLength: _usageLineLength,
),
RunCommand(
environment: environment,
configs: configs,
verbose: verbose,
usageLineLength: _usageLineLength,
),
LintCommand(
environment: environment,
usageLineLength: _usageLineLength,
),
TestCommand(
environment: environment,
configs: configs,
verbose: verbose,
usageLineLength: _usageLineLength,
),
];
commands.forEach(addCommand);

View File

@@ -11,6 +11,7 @@ final class FetchCommand extends CommandBase {
/// Constructs the 'fetch' command.
FetchCommand({
required super.environment,
super.usageLineLength,
});
@override

View File

@@ -26,6 +26,7 @@ final class FormatCommand extends CommandBase {
// ignore: public_member_api_docs
FormatCommand({
required super.environment,
super.usageLineLength,
}) {
argParser
..addFlag(

View File

@@ -41,6 +41,7 @@ final class LintCommand extends CommandBase {
/// Constructs the 'lint' command.
LintCommand({
required super.environment,
super.usageLineLength,
}) {
final String engineFlutterPath = environment.engine.flutterDir.path;
_linters[Linter.dart] = _LinterDescription(

View File

@@ -16,6 +16,7 @@ final class QueryCommand extends CommandBase {
required super.environment,
required this.configs,
super.verbose = false,
super.usageLineLength,
}) {
// Add options here that are common to all queries.
argParser

View File

@@ -19,6 +19,7 @@ final class RunCommand extends CommandBase {
required super.environment,
required Map<String, BuilderConfig> configs,
super.verbose = false,
super.usageLineLength,
}) {
builds = runnableBuilds(environment, configs, verbose);
debugCheckBuilds(builds);

View File

@@ -18,6 +18,7 @@ final class TestCommand extends CommandBase {
required super.environment,
required Map<String, BuilderConfig> configs,
super.verbose = false,
super.usageLineLength,
}) {
builds = runnableBuilds(environment, configs, verbose);
debugCheckBuilds(builds);

View File

@@ -2,6 +2,7 @@
// 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:convert' as convert;
import 'package:engine_build_configs/engine_build_configs.dart';
@@ -407,4 +408,36 @@ void main() {
testEnv.cleanup();
}
});
test('et help build line length is not too big', () async {
final List<String> prints = <String>[];
await runZoned(
() async {
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
cannedProcesses: cannedProcesses,
);
try {
final ToolCommandRunner runner = ToolCommandRunner(
environment: testEnv.environment,
configs: configs,
verbose: true,
);
final int result = await runner.run(<String>[
'help', 'build',
]);
expect(result, equals(0));
} finally {
testEnv.cleanup();
}
},
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
prints.addAll(line.split('\n'));
},
),
);
for (final String line in prints) {
expect(line.length, lessThanOrEqualTo(100));
}
});
}

View File

@@ -23,6 +23,7 @@ String testConfig(String osDimension, String osPlatform) => '''
},
"gn": ["--gn-arg", "--lto", "--goma", "--no-rbe"],
"name": "ci/build_name",
"description": "This is a very long description that will test that the help message is wrapped correctly at an appropriate number of characters.",
"ninja": {
"config": "build_name",
"targets": ["ninja_target"]