Deprecate make-host-app-editable (#59217)

This commit is contained in:
Jenn Magder 2020-06-11 11:37:15 -07:00 committed by GitHub
parent 3fc364cfbb
commit 222c2cb0cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 34 deletions

View file

@ -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<void> 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<FlutterCommandResult> 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();
}
}

View file

@ -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<void> {
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<void> {
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> {
);
}
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<void> {
description.length + 2,
);
final String help = <String>[
if (deprecated)
'$warningMark Deprecated. This command will be removed in a future version of Flutter.',
description,
'',
'Global options:',

View file

@ -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: <Type, Generator>{
Cache: () => cache,
@ -73,6 +76,21 @@ void main() {
Cache: () => cache,
});
testUsingContext('deprecated command should warn', () async {
final FakeDeprecatedCommand flutterCommand = FakeDeprecatedCommand();
final CommandRunner<void> runner = createTestCommandRunner(flutterCommand);
await runner.run(<String>['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<FlutterCommandResult> runCommand() async {

View file

@ -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(<String>[
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')));
});