Categorize flutter tool commands (#87747)

This commit is contained in:
Pierre-Louis 2021-10-06 02:28:04 +02:00 committed by GitHub
parent 0a62694532
commit 3e43c3e110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 102 additions and 1 deletions

View File

@ -105,6 +105,9 @@ class AnalyzeCommand extends FlutterCommand {
@override
String get description => "Analyze the project's Dart code.";
@override
String get category => FlutterCommandCategory.project;
@override
bool get shouldRunPub {
// If they're not analyzing the current project.

View File

@ -139,6 +139,9 @@ class AssembleCommand extends FlutterCommand {
@override
String get name => 'assemble';
@override
String get category => FlutterCommandCategory.project;
@override
Future<CustomDimensions> get usageValues async {
final FlutterProject flutterProject = FlutterProject.current();

View File

@ -144,6 +144,9 @@ If the app or module is already running and the specific observatory port is
known, it can be explicitly provided to attach via the command-line, e.g.
`$ flutter attach --debug-port 12345`''';
@override
final String category = FlutterCommandCategory.tools;
int get debugPort {
if (argResults['debug-port'] == null) {
return null;

View File

@ -57,6 +57,9 @@ class BuildCommand extends FlutterCommand {
@override
final String description = 'Build an executable app or install bundle.';
@override
String get category => FlutterCommandCategory.project;
@override
Future<FlutterCommandResult> runCommand() async => null;
}

View File

@ -27,6 +27,9 @@ class ChannelCommand extends FlutterCommand {
@override
final String description = 'List or switch Flutter channels.';
@override
final String category = FlutterCommandCategory.sdk;
@override
String get invocation => '${runner.executableName} $name [<channel-name>]';

View File

@ -29,6 +29,9 @@ class CleanCommand extends FlutterCommand {
@override
final String description = 'Delete the build/ and .dart_tool/ directories.';
@override
String get category => FlutterCommandCategory.project;
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{};

View File

@ -54,6 +54,9 @@ class ConfigCommand extends FlutterCommand {
'The Flutter tool anonymously reports feature usage statistics and basic crash reports to help improve '
"Flutter tools over time. See Google's privacy policy: https://www.google.com/intl/en/policies/privacy/";
@override
final String category = FlutterCommandCategory.sdk;
@override
final List<String> aliases = <String>['configure'];

View File

@ -78,6 +78,9 @@ class CreateCommand extends CreateBase {
final String description = 'Create a new Flutter project.\n\n'
'If run on a project that already exists, this will repair the project, recreating any files that are missing.';
@override
String get category => FlutterCommandCategory.project;
@override
String get invocation => '${runner.executableName} $name <output directory>';

View File

@ -158,6 +158,9 @@ Requires the custom devices feature to be enabled. You can enable it using "flut
@override
String get name => 'custom-devices';
@override
String get category => FlutterCommandCategory.tools;
@override
Future<FlutterCommandResult> runCommand() async => null;

View File

@ -49,6 +49,9 @@ class DaemonCommand extends FlutterCommand {
@override
final String description = 'Run a persistent, JSON-RPC based server to communicate with devices.';
@override
final String category = FlutterCommandCategory.tools;
@override
final bool hidden;

View File

@ -33,6 +33,9 @@ class DevicesCommand extends FlutterCommand {
@override
final String description = 'List all connected devices.';
@override
final String category = FlutterCommandCategory.tools;
@override
Duration get deviceDiscoveryTimeout {
if (argResults['timeout'] != null) {

View File

@ -31,6 +31,9 @@ class DoctorCommand extends FlutterCommand {
@override
final String description = 'Show information about the installed tooling.';
@override
final String category = FlutterCommandCategory.sdk;
@override
Future<FlutterCommandResult> runCommand() async {
globals.flutterVersion.fetchTagsAndUpdate();

View File

@ -76,6 +76,9 @@ class DowngradeCommand extends FlutterCommand {
@override
String get name => 'downgrade';
@override
final String category = FlutterCommandCategory.sdk;
@override
Future<FlutterCommandResult> runCommand() async {
// Commands do not necessarily have access to the correct zone injected

View File

@ -22,7 +22,7 @@ import '../device.dart';
import '../drive/drive_service.dart';
import '../globals_null_migrated.dart' as globals;
import '../resident_runner.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult, FlutterOptions;
import '../runner/flutter_command.dart' show FlutterCommandCategory, FlutterCommandResult, FlutterOptions;
import '../web/web_device.dart';
import 'run.dart';
@ -172,6 +172,9 @@ class DriveCommand extends RunCommandBase {
@override
final String description = 'Run integration tests for the project on an attached device or emulator.';
@override
String get category => FlutterCommandCategory.project;
@override
final List<String> aliases = <String>['driver'];

View File

@ -31,6 +31,9 @@ class EmulatorsCommand extends FlutterCommand {
@override
final String description = 'List, launch and create emulators.';
@override
final String category = FlutterCommandCategory.tools;
@override
final List<String> aliases = <String>['emulator'];

View File

@ -29,6 +29,9 @@ class FormatCommand extends FlutterCommand {
@override
final String description = 'Format one or more Dart files.';
@override
String get category => FlutterCommandCategory.project;
@override
String get invocation => '${runner.executableName} $name <one or more paths>';

View File

@ -194,6 +194,9 @@ class GenerateLocalizationsCommand extends FlutterCommand {
@override
String get name => 'gen-l10n';
@override
String get category => FlutterCommandCategory.project;
@override
Future<FlutterCommandResult> runCommand() async {
if (_fileSystem.file('l10n.yaml').existsSync()) {

View File

@ -30,6 +30,9 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
@override
final String description = 'Install a Flutter app on an attached device.';
@override
final String category = FlutterCommandCategory.tools;
Device device;
bool get uninstallOnly => boolArg('uninstall-only');

View File

@ -28,6 +28,9 @@ class LogsCommand extends FlutterCommand {
@override
final String description = 'Show log output for running Flutter apps.';
@override
final String category = FlutterCommandCategory.tools;
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{};

View File

@ -50,6 +50,9 @@ class PackagesCommand extends FlutterCommand {
@override
final String description = 'Commands for managing Flutter packages.';
@override
String get category => FlutterCommandCategory.project;
@override
Future<FlutterCommandResult> runCommand() async => null;
}

View File

@ -77,6 +77,9 @@ class PrecacheCommand extends FlutterCommand {
'If no explicit platform flags are provided, this command will download the artifacts '
'for all currently enabled platforms';
@override
final String category = FlutterCommandCategory.sdk;
@override
bool get shouldUpdateCache => false;

View File

@ -343,6 +343,9 @@ class RunCommand extends RunCommandBase {
@override
final String description = 'Run your Flutter app on an attached device.';
@override
String get category => FlutterCommandCategory.project;
List<Device> devices;
bool webMode = false;

View File

@ -61,6 +61,9 @@ class ScreenshotCommand extends FlutterCommand {
@override
String get description => 'Take a screenshot from a connected device.';
@override
final String category = FlutterCommandCategory.tools;
@override
final List<String> aliases = <String>['pic'];

View File

@ -31,6 +31,9 @@ class ShellCompletionCommand extends FlutterCommand {
'install it in your shell environment. Once it is sourced, your shell will be able to '
'complete flutter commands and options.';
@override
final String category = FlutterCommandCategory.sdk;
@override
final List<String> aliases = <String>['zsh-completion'];

View File

@ -59,6 +59,9 @@ class SymbolizeCommand extends FlutterCommand {
@override
String get name => 'symbolize';
@override
final String category = FlutterCommandCategory.tools;
@override
bool get shouldUpdateCache => false;

View File

@ -249,6 +249,9 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
@override
String get description => 'Run Flutter unit tests for the current project.';
@override
String get category => FlutterCommandCategory.project;
@override
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) {
_testFiles = argResults.rest.map<String>(globals.fs.path.absolute).toList();

View File

@ -63,6 +63,9 @@ class UpgradeCommand extends FlutterCommand {
@override
final String description = 'Upgrade your copy of Flutter.';
@override
final String category = FlutterCommandCategory.sdk;
@override
bool get shouldUpdateCache => false;

View File

@ -122,6 +122,13 @@ class FlutterOptions {
static const String kInitializeFromDill = 'initialize-from-dill';
}
/// flutter command categories for usage.
class FlutterCommandCategory {
static const String sdk = 'Flutter SDK';
static const String project = 'Project';
static const String tools = 'Tools & Devices';
}
abstract class FlutterCommand extends Command<void> {
/// The currently executing command (or sub-command).
///

View File

@ -7,6 +7,7 @@
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/executable.dart' as executable;
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import '../src/common.dart';
@ -34,6 +35,18 @@ void verifyCommandRunner(CommandRunner<Object> runner) {
void verifyCommand(Command<Object> runner) {
expect(runner.argParser, isNotNull, reason: 'command ${runner.name} has no argParser');
verifyOptions(runner.name, runner.argParser.options.values);
if (runner.hidden == false && runner.parent == null) {
expect(
runner.category,
anyOf(
FlutterCommandCategory.sdk,
FlutterCommandCategory.project,
FlutterCommandCategory.tools,
),
reason: "top-level command ${runner.name} doesn't have a valid category",
);
}
runner.subcommands.values.forEach(verifyCommand);
}