mirror of
https://github.com/flutter/packages.git
synced 2025-06-11 15:21:07 +08:00
[flutter_plugin_tools] Add a new base command for looping over packages (#4067)
Most of our commands are generally of the form: ``` for (each plugin as defined by the tool flags) check some things for success or failure print a summary all of the failing things exit non-zero if anything failed ``` Currently all that logic not consistent, having been at various points copied and pasted around, modified, in some cases rewritten. There's unnecessary boilerplate in each new command, and there's unnecessary variation that makes it harder both to maintain the tool, and to consume the test output: - There's no standard format for separating each plugin's run to search within a log - There's no standard format for the summary at the end - In some cases commands have been written to ToolExit on failure, which means we don't actually get the rest of the runs This makes a new base class for commands that follow this structure to use, with shared code for all the common bits. This makes it harder to accidentally write new commands incorrectly, easier to maintain the code, and lets us standardize output so that searching within large logs will be easier. This ports two commands over as a proof of concept to demonstrate that it works; more will be converted in follow-ups. Related to https://github.com/flutter/flutter/issues/83413
This commit is contained in:
@ -53,13 +53,25 @@ bool isFlutterPackage(FileSystemEntity entity) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Prints `successMessage` in green.
|
||||
void printSuccess(String successMessage) {
|
||||
print(Colorize(successMessage)..green());
|
||||
}
|
||||
|
||||
/// Prints `errorMessage` in red.
|
||||
void printError(String errorMessage) {
|
||||
final Colorize redError = Colorize(errorMessage)..red();
|
||||
print(redError);
|
||||
print(Colorize(errorMessage)..red());
|
||||
}
|
||||
|
||||
/// Error thrown when a command needs to exit with a non-zero exit code.
|
||||
///
|
||||
/// While there is no specific definition of the meaning of different non-zero
|
||||
/// exit codes for this tool, commands should follow the general convention:
|
||||
/// 1: The command ran correctly, but found errors.
|
||||
/// 2: The command failed to run because the arguments were invalid.
|
||||
/// >2: The command failed to run correctly for some other reason. Ideally,
|
||||
/// each such failure should have a unique exit code within the context of
|
||||
/// that command.
|
||||
class ToolExit extends Error {
|
||||
/// Creates a tool exit with the given [exitCode].
|
||||
ToolExit(this.exitCode);
|
||||
@ -67,3 +79,9 @@ class ToolExit extends Error {
|
||||
/// The code that the process should exit with.
|
||||
final int exitCode;
|
||||
}
|
||||
|
||||
/// A exit code for [ToolExit] for a successful run that found errors.
|
||||
const int exitCommandFoundErrors = 1;
|
||||
|
||||
/// A exit code for [ToolExit] for a failure to run due to invalid arguments.
|
||||
const int exitInvalidArguments = 2;
|
||||
|
Reference in New Issue
Block a user