diff --git a/packages/flutter_tools/lib/src/commands/make_host_app_editable.dart b/packages/flutter_tools/lib/src/commands/make_host_app_editable.dart index 2386601bc1..6b7e9e62fb 100644 --- a/packages/flutter_tools/lib/src/commands/make_host_app_editable.dart +++ b/packages/flutter_tools/lib/src/commands/make_host_app_editable.dart @@ -3,8 +3,6 @@ // found in the LICENSE file. import 'dart:async'; -import '../base/common.dart'; -import '../project.dart'; import '../runner/flutter_command.dart'; class MakeHostAppEditableCommand extends FlutterCommand { @@ -23,43 +21,18 @@ class MakeHostAppEditableCommand extends FlutterCommand { ); } - FlutterProject _project; - @override final String name = 'make-host-app-editable'; @override - final String description = 'Moves host apps from generated directories to non-generated directories so that they can be edited by developers.\n\n' - 'Use flags to specify which host app to make editable. If no flags are provided then all host apps will be made editable.\n\n' - 'Once a host app is made editable, that host app cannot be regenerated by Flutter and it will not receive future template changes.'; + bool get deprecated => true; @override - Future validateCommand() async { - await super.validateCommand(); - _project = FlutterProject.current(); - if (!_project.isModule) { - throw ToolExit("Only projects created using 'flutter create -t module' can have their host apps made editable."); - } - } + final String description = 'Moves host apps from generated directories to non-generated directories so that they can be edited by developers.'; @override Future runCommand() async { - await _project.ensureReadyForPlatformSpecificTooling(checkProjects: false); - - final bool isAndroidRequested = boolArg('android'); - final bool isIOSRequested = boolArg('ios'); - - if (isAndroidRequested == isIOSRequested) { - // No flags provided, or both flags provided. Make Android and iOS host - // apps editable. - await _project.android.makeHostAppEditable(); - await _project.ios.makeHostAppEditable(); - } else if (isAndroidRequested) { - await _project.android.makeHostAppEditable(); - } else if (isIOSRequested) { - await _project.ios.makeHostAppEditable(); - } - + // Deprecated. No-op. return FlutterCommandResult.success(); } } diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index c603065c00..dcbb6eca10 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -15,6 +15,7 @@ import '../base/common.dart'; import '../base/context.dart'; import '../base/io.dart' as io; import '../base/signals.dart'; +import '../base/terminal.dart'; import '../base/user_messages.dart'; import '../base/utils.dart'; import '../build_info.dart'; @@ -150,6 +151,11 @@ abstract class FlutterCommand extends Command { bool get shouldUpdateCache => true; + bool get deprecated => false; + + @override + bool get hidden => deprecated; + bool _excludeDebug = false; BuildMode _defaultBuildMode; @@ -715,6 +721,7 @@ abstract class FlutterCommand extends Command { body: () async { // Prints the welcome message if needed. globals.flutterUsage.printWelcome(); + _printDeprecationWarning(); final String commandPath = await usagePath; _registerSignalHandlers(commandPath, startTime); FlutterCommandResult commandResult = FlutterCommandResult.fail(); @@ -729,6 +736,14 @@ abstract class FlutterCommand extends Command { ); } + void _printDeprecationWarning() { + if (deprecated) { + globals.printStatus('$warningMark The "$name" command is deprecated and ' + 'will be removed in a future version of Flutter.'); + globals.printStatus(''); + } + } + void _registerSignalHandlers(String commandPath, DateTime startTime) { final SignalHandler handler = (io.ProcessSignal s) { Cache.releaseLock(); @@ -948,6 +963,8 @@ abstract class FlutterCommand extends Command { description.length + 2, ); final String help = [ + if (deprecated) + '$warningMark Deprecated. This command will be removed in a future version of Flutter.', description, '', 'Global options:', diff --git a/packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart b/packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart index 9f8e27349c..c6779d46ab 100644 --- a/packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart +++ b/packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'dart:io' as io; +import 'package:args/command_runner.dart'; import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/error_handling_file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; @@ -43,7 +44,7 @@ void main() { }); testUsingContext('help text contains global options', () { - final FakeCommand fake = FakeCommand(); + final FakeDeprecatedCommand fake = FakeDeprecatedCommand(); createTestCommandRunner(fake); expect(fake.usage, contains('Global options:\n')); }); @@ -52,6 +53,8 @@ void main() { final DummyFlutterCommand flutterCommand = DummyFlutterCommand(shouldUpdateCache: false); await flutterCommand.run(); verifyZeroInteractions(cache); + expect(flutterCommand.deprecated, isFalse); + expect(flutterCommand.hidden, isFalse); }, overrides: { Cache: () => cache, @@ -73,6 +76,21 @@ void main() { Cache: () => cache, }); + testUsingContext('deprecated command should warn', () async { + final FakeDeprecatedCommand flutterCommand = FakeDeprecatedCommand(); + final CommandRunner runner = createTestCommandRunner(flutterCommand); + await runner.run(['deprecated']); + + expect(testLogger.statusText, + contains('The "deprecated" command is deprecated and will be removed in ' + 'a future version of Flutter.')); + expect(flutterCommand.usage, + contains('Deprecated. This command will be removed in a future version ' + 'of Flutter.')); + expect(flutterCommand.deprecated, isTrue); + expect(flutterCommand.hidden, isTrue); + }); + testUsingContext('uses the error handling file system', () async { final DummyFlutterCommand flutterCommand = DummyFlutterCommand( commandFunction: () async { @@ -429,12 +447,15 @@ void main() { }); } -class FakeCommand extends FlutterCommand { +class FakeDeprecatedCommand extends FlutterCommand { @override String get description => 'A fake command'; @override - String get name => 'fake'; + String get name => 'deprecated'; + + @override + bool get deprecated => true; @override Future runCommand() async { diff --git a/packages/flutter_tools/test/integration.shard/command_output_test.dart b/packages/flutter_tools/test/integration.shard/command_output_test.dart index 086323dece..ba4d967bf1 100644 --- a/packages/flutter_tools/test/integration.shard/command_output_test.dart +++ b/packages/flutter_tools/test/integration.shard/command_output_test.dart @@ -9,7 +9,7 @@ import 'package:process/process.dart'; import '../src/common.dart'; void main() { - test('All development tools are hidden and help text is not verbose', () async { + test('All development tools and deprecated commands are hidden and help text is not verbose', () async { final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', 'flutter'); final ProcessResult result = await const LocalProcessManager().run([ flutterBin, @@ -17,9 +17,14 @@ void main() { '-v', ]); + // Development tools. expect(result.stdout, isNot(contains('ide-config'))); expect(result.stdout, isNot(contains('update-packages'))); expect(result.stdout, isNot(contains('inject-plugins'))); + + // Deprecated. + expect(result.stdout, isNot(contains('make-host-app-editable'))); + // Only printed by verbose tool. expect(result.stdout, isNot(contains('exiting with code 0'))); });