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 9e51d6816e..2eee49b64f 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,43 +3,35 @@ // found in the LICENSE file. import 'dart:async'; -import 'package:meta/meta.dart'; import '../base/common.dart'; import '../project.dart'; import '../runner/flutter_command.dart'; class MakeHostAppEditableCommand extends FlutterCommand { MakeHostAppEditableCommand() { - addSubcommand(MakeHostAppEditableAndroidCommand()); - addSubcommand(MakeHostAppEditableIosCommand()); - } - - @override - final String name = 'make-host-app-editable'; - - @override - final String description = 'Commands for making host apps editable within a Flutter project'; - - @override - bool get hidden => true; - - @override - Future runCommand() async => null; -} - -abstract class MakeHostAppEditableSubCommand extends FlutterCommand { - MakeHostAppEditableSubCommand() { requiresPubspecYaml(); + + argParser.addFlag( + 'ios', + help: 'Whether to make this project\'s iOS app editable.', + negatable: false, + ); + argParser.addFlag( + 'android', + help: 'Whether ot make this project\'s Android app editable.', + negatable: false, + ); } FlutterProject _project; @override - @mustCallSuper - Future runCommand() async { - await _project.ensureReadyForPlatformSpecificTooling(); - return null; - } + 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.'; @override Future validateCommand() async { @@ -48,36 +40,23 @@ abstract class MakeHostAppEditableSubCommand extends FlutterCommand { if (!_project.isApplication) throw ToolExit("Only projects created using 'flutter create -t application' can have their host apps made editable."); } -} - -class MakeHostAppEditableAndroidCommand extends MakeHostAppEditableSubCommand { - @override - String get name => 'android'; @override - String get description => 'Make an Android host app editable within a Flutter project'; + Future runCommand() async { + await _project.ensureReadyForPlatformSpecificTooling(); - @override - Future runCommand() async { - await super.runCommand(); - await _project.android.makeHostAppEditable(); + final bool isAndroidRequested = argResults['android']; + final bool isIOSRequested = argResults['ios']; - return null; - } -} - -class MakeHostAppEditableIosCommand extends MakeHostAppEditableSubCommand { - @override - String get name => 'ios'; - - @override - String get description => 'Make an iOS host app editable within a Flutter project'; - - @override - Future runCommand() async { - await super.runCommand(); - await _project.ios.makeHostAppEditable(); - - return null; + 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(); + } } }