Unverified Commit 3e43c3e1 authored by Pierre-Louis's avatar Pierre-Louis Committed by GitHub

Categorize flutter tool commands (#87747)

parent 0a626945
...@@ -105,6 +105,9 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -105,6 +105,9 @@ class AnalyzeCommand extends FlutterCommand {
@override @override
String get description => "Analyze the project's Dart code."; String get description => "Analyze the project's Dart code.";
@override
String get category => FlutterCommandCategory.project;
@override @override
bool get shouldRunPub { bool get shouldRunPub {
// If they're not analyzing the current project. // If they're not analyzing the current project.
......
...@@ -139,6 +139,9 @@ class AssembleCommand extends FlutterCommand { ...@@ -139,6 +139,9 @@ class AssembleCommand extends FlutterCommand {
@override @override
String get name => 'assemble'; String get name => 'assemble';
@override
String get category => FlutterCommandCategory.project;
@override @override
Future<CustomDimensions> get usageValues async { Future<CustomDimensions> get usageValues async {
final FlutterProject flutterProject = FlutterProject.current(); final FlutterProject flutterProject = FlutterProject.current();
......
...@@ -144,6 +144,9 @@ If the app or module is already running and the specific observatory port is ...@@ -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. known, it can be explicitly provided to attach via the command-line, e.g.
`$ flutter attach --debug-port 12345`'''; `$ flutter attach --debug-port 12345`''';
@override
final String category = FlutterCommandCategory.tools;
int get debugPort { int get debugPort {
if (argResults['debug-port'] == null) { if (argResults['debug-port'] == null) {
return null; return null;
......
...@@ -57,6 +57,9 @@ class BuildCommand extends FlutterCommand { ...@@ -57,6 +57,9 @@ class BuildCommand extends FlutterCommand {
@override @override
final String description = 'Build an executable app or install bundle.'; final String description = 'Build an executable app or install bundle.';
@override
String get category => FlutterCommandCategory.project;
@override @override
Future<FlutterCommandResult> runCommand() async => null; Future<FlutterCommandResult> runCommand() async => null;
} }
......
...@@ -27,6 +27,9 @@ class ChannelCommand extends FlutterCommand { ...@@ -27,6 +27,9 @@ class ChannelCommand extends FlutterCommand {
@override @override
final String description = 'List or switch Flutter channels.'; final String description = 'List or switch Flutter channels.';
@override
final String category = FlutterCommandCategory.sdk;
@override @override
String get invocation => '${runner.executableName} $name [<channel-name>]'; String get invocation => '${runner.executableName} $name [<channel-name>]';
......
...@@ -29,6 +29,9 @@ class CleanCommand extends FlutterCommand { ...@@ -29,6 +29,9 @@ class CleanCommand extends FlutterCommand {
@override @override
final String description = 'Delete the build/ and .dart_tool/ directories.'; final String description = 'Delete the build/ and .dart_tool/ directories.';
@override
String get category => FlutterCommandCategory.project;
@override @override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{}; Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{};
......
...@@ -54,6 +54,9 @@ class ConfigCommand extends FlutterCommand { ...@@ -54,6 +54,9 @@ class ConfigCommand extends FlutterCommand {
'The Flutter tool anonymously reports feature usage statistics and basic crash reports to help improve ' '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/"; "Flutter tools over time. See Google's privacy policy: https://www.google.com/intl/en/policies/privacy/";
@override
final String category = FlutterCommandCategory.sdk;
@override @override
final List<String> aliases = <String>['configure']; final List<String> aliases = <String>['configure'];
......
...@@ -78,6 +78,9 @@ class CreateCommand extends CreateBase { ...@@ -78,6 +78,9 @@ class CreateCommand extends CreateBase {
final String description = 'Create a new Flutter project.\n\n' 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.'; '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 @override
String get invocation => '${runner.executableName} $name <output directory>'; String get invocation => '${runner.executableName} $name <output directory>';
......
...@@ -158,6 +158,9 @@ Requires the custom devices feature to be enabled. You can enable it using "flut ...@@ -158,6 +158,9 @@ Requires the custom devices feature to be enabled. You can enable it using "flut
@override @override
String get name => 'custom-devices'; String get name => 'custom-devices';
@override
String get category => FlutterCommandCategory.tools;
@override @override
Future<FlutterCommandResult> runCommand() async => null; Future<FlutterCommandResult> runCommand() async => null;
......
...@@ -49,6 +49,9 @@ class DaemonCommand extends FlutterCommand { ...@@ -49,6 +49,9 @@ class DaemonCommand extends FlutterCommand {
@override @override
final String description = 'Run a persistent, JSON-RPC based server to communicate with devices.'; final String description = 'Run a persistent, JSON-RPC based server to communicate with devices.';
@override
final String category = FlutterCommandCategory.tools;
@override @override
final bool hidden; final bool hidden;
......
...@@ -33,6 +33,9 @@ class DevicesCommand extends FlutterCommand { ...@@ -33,6 +33,9 @@ class DevicesCommand extends FlutterCommand {
@override @override
final String description = 'List all connected devices.'; final String description = 'List all connected devices.';
@override
final String category = FlutterCommandCategory.tools;
@override @override
Duration get deviceDiscoveryTimeout { Duration get deviceDiscoveryTimeout {
if (argResults['timeout'] != null) { if (argResults['timeout'] != null) {
......
...@@ -31,6 +31,9 @@ class DoctorCommand extends FlutterCommand { ...@@ -31,6 +31,9 @@ class DoctorCommand extends FlutterCommand {
@override @override
final String description = 'Show information about the installed tooling.'; final String description = 'Show information about the installed tooling.';
@override
final String category = FlutterCommandCategory.sdk;
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
globals.flutterVersion.fetchTagsAndUpdate(); globals.flutterVersion.fetchTagsAndUpdate();
......
...@@ -76,6 +76,9 @@ class DowngradeCommand extends FlutterCommand { ...@@ -76,6 +76,9 @@ class DowngradeCommand extends FlutterCommand {
@override @override
String get name => 'downgrade'; String get name => 'downgrade';
@override
final String category = FlutterCommandCategory.sdk;
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
// Commands do not necessarily have access to the correct zone injected // Commands do not necessarily have access to the correct zone injected
......
...@@ -22,7 +22,7 @@ import '../device.dart'; ...@@ -22,7 +22,7 @@ import '../device.dart';
import '../drive/drive_service.dart'; import '../drive/drive_service.dart';
import '../globals_null_migrated.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../resident_runner.dart'; 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 '../web/web_device.dart';
import 'run.dart'; import 'run.dart';
...@@ -172,6 +172,9 @@ class DriveCommand extends RunCommandBase { ...@@ -172,6 +172,9 @@ class DriveCommand extends RunCommandBase {
@override @override
final String description = 'Run integration tests for the project on an attached device or emulator.'; final String description = 'Run integration tests for the project on an attached device or emulator.';
@override
String get category => FlutterCommandCategory.project;
@override @override
final List<String> aliases = <String>['driver']; final List<String> aliases = <String>['driver'];
......
...@@ -31,6 +31,9 @@ class EmulatorsCommand extends FlutterCommand { ...@@ -31,6 +31,9 @@ class EmulatorsCommand extends FlutterCommand {
@override @override
final String description = 'List, launch and create emulators.'; final String description = 'List, launch and create emulators.';
@override
final String category = FlutterCommandCategory.tools;
@override @override
final List<String> aliases = <String>['emulator']; final List<String> aliases = <String>['emulator'];
......
...@@ -29,6 +29,9 @@ class FormatCommand extends FlutterCommand { ...@@ -29,6 +29,9 @@ class FormatCommand extends FlutterCommand {
@override @override
final String description = 'Format one or more Dart files.'; final String description = 'Format one or more Dart files.';
@override
String get category => FlutterCommandCategory.project;
@override @override
String get invocation => '${runner.executableName} $name <one or more paths>'; String get invocation => '${runner.executableName} $name <one or more paths>';
......
...@@ -194,6 +194,9 @@ class GenerateLocalizationsCommand extends FlutterCommand { ...@@ -194,6 +194,9 @@ class GenerateLocalizationsCommand extends FlutterCommand {
@override @override
String get name => 'gen-l10n'; String get name => 'gen-l10n';
@override
String get category => FlutterCommandCategory.project;
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
if (_fileSystem.file('l10n.yaml').existsSync()) { if (_fileSystem.file('l10n.yaml').existsSync()) {
......
...@@ -30,6 +30,9 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts ...@@ -30,6 +30,9 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
@override @override
final String description = 'Install a Flutter app on an attached device.'; final String description = 'Install a Flutter app on an attached device.';
@override
final String category = FlutterCommandCategory.tools;
Device device; Device device;
bool get uninstallOnly => boolArg('uninstall-only'); bool get uninstallOnly => boolArg('uninstall-only');
......
...@@ -28,6 +28,9 @@ class LogsCommand extends FlutterCommand { ...@@ -28,6 +28,9 @@ class LogsCommand extends FlutterCommand {
@override @override
final String description = 'Show log output for running Flutter apps.'; final String description = 'Show log output for running Flutter apps.';
@override
final String category = FlutterCommandCategory.tools;
@override @override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{}; Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{};
......
...@@ -50,6 +50,9 @@ class PackagesCommand extends FlutterCommand { ...@@ -50,6 +50,9 @@ class PackagesCommand extends FlutterCommand {
@override @override
final String description = 'Commands for managing Flutter packages.'; final String description = 'Commands for managing Flutter packages.';
@override
String get category => FlutterCommandCategory.project;
@override @override
Future<FlutterCommandResult> runCommand() async => null; Future<FlutterCommandResult> runCommand() async => null;
} }
......
...@@ -77,6 +77,9 @@ class PrecacheCommand extends FlutterCommand { ...@@ -77,6 +77,9 @@ class PrecacheCommand extends FlutterCommand {
'If no explicit platform flags are provided, this command will download the artifacts ' 'If no explicit platform flags are provided, this command will download the artifacts '
'for all currently enabled platforms'; 'for all currently enabled platforms';
@override
final String category = FlutterCommandCategory.sdk;
@override @override
bool get shouldUpdateCache => false; bool get shouldUpdateCache => false;
......
...@@ -343,6 +343,9 @@ class RunCommand extends RunCommandBase { ...@@ -343,6 +343,9 @@ class RunCommand extends RunCommandBase {
@override @override
final String description = 'Run your Flutter app on an attached device.'; final String description = 'Run your Flutter app on an attached device.';
@override
String get category => FlutterCommandCategory.project;
List<Device> devices; List<Device> devices;
bool webMode = false; bool webMode = false;
......
...@@ -61,6 +61,9 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -61,6 +61,9 @@ class ScreenshotCommand extends FlutterCommand {
@override @override
String get description => 'Take a screenshot from a connected device.'; String get description => 'Take a screenshot from a connected device.';
@override
final String category = FlutterCommandCategory.tools;
@override @override
final List<String> aliases = <String>['pic']; final List<String> aliases = <String>['pic'];
......
...@@ -31,6 +31,9 @@ class ShellCompletionCommand extends FlutterCommand { ...@@ -31,6 +31,9 @@ class ShellCompletionCommand extends FlutterCommand {
'install it in your shell environment. Once it is sourced, your shell will be able to ' 'install it in your shell environment. Once it is sourced, your shell will be able to '
'complete flutter commands and options.'; 'complete flutter commands and options.';
@override
final String category = FlutterCommandCategory.sdk;
@override @override
final List<String> aliases = <String>['zsh-completion']; final List<String> aliases = <String>['zsh-completion'];
......
...@@ -59,6 +59,9 @@ class SymbolizeCommand extends FlutterCommand { ...@@ -59,6 +59,9 @@ class SymbolizeCommand extends FlutterCommand {
@override @override
String get name => 'symbolize'; String get name => 'symbolize';
@override
final String category = FlutterCommandCategory.tools;
@override @override
bool get shouldUpdateCache => false; bool get shouldUpdateCache => false;
......
...@@ -249,6 +249,9 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts { ...@@ -249,6 +249,9 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
@override @override
String get description => 'Run Flutter unit tests for the current project.'; String get description => 'Run Flutter unit tests for the current project.';
@override
String get category => FlutterCommandCategory.project;
@override @override
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) { Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) {
_testFiles = argResults.rest.map<String>(globals.fs.path.absolute).toList(); _testFiles = argResults.rest.map<String>(globals.fs.path.absolute).toList();
......
...@@ -63,6 +63,9 @@ class UpgradeCommand extends FlutterCommand { ...@@ -63,6 +63,9 @@ class UpgradeCommand extends FlutterCommand {
@override @override
final String description = 'Upgrade your copy of Flutter.'; final String description = 'Upgrade your copy of Flutter.';
@override
final String category = FlutterCommandCategory.sdk;
@override @override
bool get shouldUpdateCache => false; bool get shouldUpdateCache => false;
......
...@@ -122,6 +122,13 @@ class FlutterOptions { ...@@ -122,6 +122,13 @@ class FlutterOptions {
static const String kInitializeFromDill = 'initialize-from-dill'; 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> { abstract class FlutterCommand extends Command<void> {
/// The currently executing command (or sub-command). /// The currently executing command (or sub-command).
/// ///
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import 'package:args/args.dart'; import 'package:args/args.dart';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:flutter_tools/executable.dart' as executable; 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 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import '../src/common.dart'; import '../src/common.dart';
...@@ -34,6 +35,18 @@ void verifyCommandRunner(CommandRunner<Object> runner) { ...@@ -34,6 +35,18 @@ void verifyCommandRunner(CommandRunner<Object> runner) {
void verifyCommand(Command<Object> runner) { void verifyCommand(Command<Object> runner) {
expect(runner.argParser, isNotNull, reason: 'command ${runner.name} has no argParser'); expect(runner.argParser, isNotNull, reason: 'command ${runner.name} has no argParser');
verifyOptions(runner.name, runner.argParser.options.values); 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); runner.subcommands.values.forEach(verifyCommand);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment