Reland [flutter_tools] show only supported sub commands (#86153)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
@@ -11,6 +12,7 @@ import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build.dart';
|
||||
import 'package:flutter_tools/src/commands/build_fuchsia.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/fuchsia_kernel_compiler.dart';
|
||||
import 'package:flutter_tools/src/fuchsia/fuchsia_pm.dart';
|
||||
@@ -109,9 +111,10 @@ void main() {
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
pubspecFile.writeAsStringSync('name: $appName');
|
||||
|
||||
final bool supported = BuildFuchsiaCommand(verboseHelp: false).supported;
|
||||
expect(
|
||||
createTestCommandRunner(command).run(const <String>['build', 'fuchsia']),
|
||||
throwsToolExit(),
|
||||
supported ? throwsToolExit() : throwsA(isA<UsageException>()),
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => windowsPlatform,
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build.dart';
|
||||
import 'package:flutter_tools/src/commands/build_ios.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
@@ -160,9 +162,10 @@ void main() {
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart'))
|
||||
.createSync(recursive: true);
|
||||
|
||||
final bool supported = BuildIOSCommand(verboseHelp: false).supported;
|
||||
expect(createTestCommandRunner(command).run(
|
||||
const <String>['build', 'ios', '--no-pub']
|
||||
), throwsToolExit());
|
||||
), supported ? throwsToolExit() : throwsA(isA<UsageException>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => notMacosPlatform,
|
||||
FileSystem: () => fileSystem,
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build.dart';
|
||||
import 'package:flutter_tools/src/commands/build_ios.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
@@ -155,9 +157,10 @@ void main() {
|
||||
fileSystem.file(fileSystem.path.join('lib', 'main.dart'))
|
||||
.createSync(recursive: true);
|
||||
|
||||
final bool supported = BuildIOSArchiveCommand(verboseHelp: false).supported;
|
||||
expect(createTestCommandRunner(command).run(
|
||||
const <String>['build', 'ipa', '--no-pub']
|
||||
), throwsToolExit());
|
||||
), supported ? throwsToolExit() : throwsA(isA<UsageException>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => notMacosPlatform,
|
||||
FileSystem: () => fileSystem,
|
||||
|
||||
@@ -149,7 +149,7 @@ void main() {
|
||||
|
||||
expect(createTestCommandRunner(command).run(
|
||||
const <String>['build', 'macos', '--no-pub']
|
||||
), throwsToolExit(message: '"build macos" only supported on macOS hosts.'));
|
||||
), throwsA(isA<UsageException>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => notMacosPlatform,
|
||||
FileSystem: () => fileSystem,
|
||||
@@ -390,8 +390,9 @@ void main() {
|
||||
testUsingContext('Refuses to build for macOS when feature is disabled', () {
|
||||
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand());
|
||||
|
||||
final bool supported = BuildMacosCommand(verboseHelp: false).supported;
|
||||
expect(() => runner.run(<String>['build', 'macos', '--no-pub']),
|
||||
throwsToolExit());
|
||||
supported ? throwsToolExit() : throwsA(isA<UsageException>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: false),
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/commands/attach.dart';
|
||||
import 'package:flutter_tools/src/commands/build.dart';
|
||||
@@ -75,6 +76,13 @@ void main() {
|
||||
FakeBuildSubCommand().test(sound);
|
||||
expect(testLogger.statusText, contains('💪 Building with sound null safety 💪'));
|
||||
});
|
||||
|
||||
testUsingContext('Include only supported sub commands', () {
|
||||
final BuildCommand command = BuildCommand();
|
||||
for (final Command<void> x in command.subcommands.values) {
|
||||
expect((x as BuildSubCommand).supported, isTrue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class FakeBuildSubCommand extends BuildSubCommand {
|
||||
|
||||
Reference in New Issue
Block a user