mirror of
https://github.com/flutter/flutter
synced 2024-07-17 02:48:33 +00:00
[flutter_tools] add deprecation message for "flutter format" (#116145)
This commit is contained in:
parent
a29796e339
commit
2ef2cc89e9
|
@ -32,6 +32,17 @@ class FormatCommand extends FlutterCommand {
|
||||||
@override
|
@override
|
||||||
String get invocation => '${runner?.executableName} $name <one or more paths>';
|
String get invocation => '${runner?.executableName} $name <one or more paths>';
|
||||||
|
|
||||||
|
@override
|
||||||
|
final bool deprecated = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get deprecationWarning {
|
||||||
|
return '${globals.logger.terminal.warningMark} The "format" command is '
|
||||||
|
'deprecated and will be removed in a future version of Flutter. '
|
||||||
|
'Please use the "dart format" sub-command instead, which takes all '
|
||||||
|
'of the same command-line arguments as "flutter format".\n';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FlutterCommandResult> runCommand() async {
|
Future<FlutterCommandResult> runCommand() async {
|
||||||
final String dartBinary = globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path;
|
final String dartBinary = globals.artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path;
|
||||||
|
|
|
@ -1269,14 +1269,17 @@ abstract class FlutterCommand extends Command<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@visibleForOverriding
|
||||||
|
String get deprecationWarning {
|
||||||
|
return '${globals.logger.terminal.warningMark} The "$name" command is '
|
||||||
|
'deprecated and will be removed in a future version of Flutter. '
|
||||||
|
'See https://flutter.dev/docs/development/tools/sdk/releases '
|
||||||
|
'for previous releases of Flutter.\n';
|
||||||
|
}
|
||||||
|
|
||||||
void _printDeprecationWarning() {
|
void _printDeprecationWarning() {
|
||||||
if (deprecated) {
|
if (deprecated) {
|
||||||
globals.printWarning(
|
globals.printWarning(deprecationWarning);
|
||||||
'${globals.logger.terminal.warningMark} The "$name" command is deprecated and '
|
|
||||||
'will be removed in a future version of Flutter. '
|
|
||||||
'See https://flutter.dev/docs/development/tools/sdk/releases '
|
|
||||||
'for previous releases of Flutter.\n',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,31 +4,48 @@
|
||||||
|
|
||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
import 'package:flutter_tools/src/base/file_system.dart';
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
import 'package:flutter_tools/src/base/io.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/cache.dart';
|
import 'package:flutter_tools/src/cache.dart';
|
||||||
import 'package:flutter_tools/src/commands/format.dart';
|
import 'package:flutter_tools/src/commands/format.dart';
|
||||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||||
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/context.dart';
|
import '../../src/context.dart';
|
||||||
import '../../src/fakes.dart';
|
|
||||||
import '../../src/test_flutter_command_runner.dart';
|
import '../../src/test_flutter_command_runner.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('format', () {
|
group('format', () {
|
||||||
late Directory tempDir;
|
late Directory tempDir;
|
||||||
late FakeStdio mockStdio;
|
late BufferLogger logger;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
Cache.disableLocking();
|
Cache.disableLocking();
|
||||||
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_format_test.');
|
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_format_test.');
|
||||||
mockStdio = FakeStdio();
|
logger = BufferLogger.test();
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
tryToDelete(tempDir);
|
tryToDelete(tempDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('shows deprecation warning', () async {
|
||||||
|
final String projectPath = await createProject(tempDir);
|
||||||
|
|
||||||
|
final File srcFile = globals.fs.file(globals.fs.path.join(projectPath, 'lib', 'main.dart'));
|
||||||
|
final String original = srcFile.readAsStringSync();
|
||||||
|
srcFile.writeAsStringSync(original);
|
||||||
|
|
||||||
|
final FormatCommand command = FormatCommand(verboseHelp: false);
|
||||||
|
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||||
|
await runner.run(<String>['format', srcFile.path]);
|
||||||
|
expect(
|
||||||
|
logger.warningText,
|
||||||
|
contains('The "format" command is deprecated and will be removed in a future version of Flutter'),
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
Logger: () => logger,
|
||||||
|
});
|
||||||
|
|
||||||
testUsingContext('a file', () async {
|
testUsingContext('a file', () async {
|
||||||
final String projectPath = await createProject(tempDir);
|
final String projectPath = await createProject(tempDir);
|
||||||
|
|
||||||
|
@ -43,7 +60,7 @@ void main() {
|
||||||
final String formatted = srcFile.readAsStringSync();
|
final String formatted = srcFile.readAsStringSync();
|
||||||
expect(formatted, original);
|
expect(formatted, original);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
Stdio: () => mockStdio,
|
Logger: () => logger,
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('dry-run', () async {
|
testUsingContext('dry-run', () async {
|
||||||
|
@ -61,6 +78,8 @@ void main() {
|
||||||
|
|
||||||
final String shouldNotFormatted = srcFile.readAsStringSync();
|
final String shouldNotFormatted = srcFile.readAsStringSync();
|
||||||
expect(shouldNotFormatted, nonFormatted);
|
expect(shouldNotFormatted, nonFormatted);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
Logger: () => logger,
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('dry-run with -n', () async {
|
testUsingContext('dry-run with -n', () async {
|
||||||
|
|
Loading…
Reference in a new issue