From 0b6ce345a30603af09608e2b518bf495c256b55f Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Thu, 11 Apr 2024 08:39:05 -0700 Subject: [PATCH] [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. --- .../lib/src/commands/build_command.dart | 1 + .../engine_tool/lib/src/commands/command.dart | 6 ++- .../lib/src/commands/command_runner.dart | 45 +++++++++++++++---- .../lib/src/commands/fetch_command.dart | 1 + .../lib/src/commands/format_command.dart | 1 + .../lib/src/commands/lint_command.dart | 1 + .../lib/src/commands/query_command.dart | 1 + .../lib/src/commands/run_command.dart | 1 + .../lib/src/commands/test_command.dart | 1 + .../engine_tool/test/build_command_test.dart | 33 ++++++++++++++ .../tools/engine_tool/test/fixtures.dart | 1 + 11 files changed, 83 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/build_command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/build_command.dart index 225c5dae53..86241f56ab 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/build_command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/build_command.dart @@ -16,6 +16,7 @@ final class BuildCommand extends CommandBase { required super.environment, required Map configs, super.verbose = false, + super.usageLineLength, }) { builds = runnableBuilds(environment, configs, verbose); debugCheckBuilds(builds); diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/command.dart index a007389965..cc52d05937 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/command.dart @@ -16,13 +16,17 @@ abstract base class CommandBase extends Command { 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. diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/command_runner.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/command_runner.dart index cd72a4612b..b377ea5b5e 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/command_runner.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/command_runner.dart @@ -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 { @@ -28,13 +28,42 @@ final class ToolCommandRunner extends CommandRunner { this.verbose = false, }) : super(toolName, toolDescription, usageLineLength: _usageLineLength) { final List> commands = >[ - 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); diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/fetch_command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/fetch_command.dart index 7cdfd0cd65..f53557f851 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/fetch_command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/fetch_command.dart @@ -11,6 +11,7 @@ final class FetchCommand extends CommandBase { /// Constructs the 'fetch' command. FetchCommand({ required super.environment, + super.usageLineLength, }); @override diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/format_command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/format_command.dart index aefb91becb..d9cc7f2399 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/format_command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/format_command.dart @@ -26,6 +26,7 @@ final class FormatCommand extends CommandBase { // ignore: public_member_api_docs FormatCommand({ required super.environment, + super.usageLineLength, }) { argParser ..addFlag( diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/lint_command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/lint_command.dart index 75989a4ff1..1800ddd28b 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/lint_command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/lint_command.dart @@ -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( diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/query_command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/query_command.dart index b7d00d0ab0..a893d316de 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/query_command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/query_command.dart @@ -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 diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/run_command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/run_command.dart index a2bbf9ccc0..f824bcd1f2 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/run_command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/run_command.dart @@ -19,6 +19,7 @@ final class RunCommand extends CommandBase { required super.environment, required Map configs, super.verbose = false, + super.usageLineLength, }) { builds = runnableBuilds(environment, configs, verbose); debugCheckBuilds(builds); diff --git a/engine/src/flutter/tools/engine_tool/lib/src/commands/test_command.dart b/engine/src/flutter/tools/engine_tool/lib/src/commands/test_command.dart index e2604d33a9..20381fb171 100644 --- a/engine/src/flutter/tools/engine_tool/lib/src/commands/test_command.dart +++ b/engine/src/flutter/tools/engine_tool/lib/src/commands/test_command.dart @@ -18,6 +18,7 @@ final class TestCommand extends CommandBase { required super.environment, required Map configs, super.verbose = false, + super.usageLineLength, }) { builds = runnableBuilds(environment, configs, verbose); debugCheckBuilds(builds); diff --git a/engine/src/flutter/tools/engine_tool/test/build_command_test.dart b/engine/src/flutter/tools/engine_tool/test/build_command_test.dart index aea136573f..fe1c65f8e1 100644 --- a/engine/src/flutter/tools/engine_tool/test/build_command_test.dart +++ b/engine/src/flutter/tools/engine_tool/test/build_command_test.dart @@ -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 prints = []; + 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([ + '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)); + } + }); } diff --git a/engine/src/flutter/tools/engine_tool/test/fixtures.dart b/engine/src/flutter/tools/engine_tool/test/fixtures.dart index c2ba3ba91b..53e088d3b2 100644 --- a/engine/src/flutter/tools/engine_tool/test/fixtures.dart +++ b/engine/src/flutter/tools/engine_tool/test/fixtures.dart @@ -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"]