4
4
5
5
import 'dart:async' ;
6
6
7
+ import 'package:args/args.dart' ;
8
+
9
+ import '../artifacts.dart' ;
7
10
import '../base/common.dart' ;
8
11
import '../base/process.dart' ;
9
- import '../dart/sdk .dart' ;
12
+ import '../globals .dart' as globals ;
10
13
import '../runner/flutter_command.dart' ;
11
14
12
15
class FormatCommand extends FlutterCommand {
13
- FormatCommand () {
14
- argParser.addFlag ('dry-run' ,
15
- abbr: 'n' ,
16
- help: 'Show which files would be modified but make no changes.' ,
17
- defaultsTo: false ,
18
- negatable: false ,
19
- );
20
- argParser.addFlag ('set-exit-if-changed' ,
21
- help: 'Return exit code 1 if there are any formatting changes.' ,
22
- defaultsTo: false ,
23
- negatable: false ,
24
- );
25
- argParser.addFlag ('machine' ,
26
- abbr: 'm' ,
27
- help: 'Produce machine-readable JSON output.' ,
28
- defaultsTo: false ,
29
- negatable: false ,
30
- );
31
- argParser.addOption ('line-length' ,
32
- abbr: 'l' ,
33
- help: 'Wrap lines longer than this length. Defaults to 80 characters.' ,
34
- defaultsTo: '80' ,
35
- );
36
- }
16
+ @override
17
+ ArgParser get argParser => _argParser;
18
+ final ArgParser _argParser = ArgParser .allowAnything ();
37
19
38
20
@override
39
21
final String name = 'format' ;
@@ -48,34 +30,25 @@ class FormatCommand extends FlutterCommand {
48
30
String get invocation => '${runner .executableName } $name <one or more paths>' ;
49
31
50
32
@override
51
- Future <FlutterCommandResult > runCommand () async {
52
- if (argResults.rest.isEmpty) {
53
- throwToolExit (
54
- 'No files specified to be formatted.\n '
55
- '\n '
56
- 'To format all files in the current directory tree:\n '
57
- '${runner .executableName } $name .\n '
58
- '\n '
59
- '$usage '
60
- );
61
- }
33
+ bool get shouldUpdateCache => false ;
62
34
63
- final String dartfmt = sdkBinaryName ('dartfmt' );
35
+ @override
36
+ Future <FlutterCommandResult > runCommand () async {
37
+ final String dartBinary = globals.artifacts.getArtifactPath (Artifact .engineDartBinary);
38
+ globals.printError (
39
+ '"flutter format" is deprecated and will be removed in a'
40
+ ' future release, use "dart format" instead.'
41
+ );
64
42
final List <String > command = < String > [
65
- dartfmt,
66
- if (boolArg ('dry-run' )) '-n' ,
67
- if (boolArg ('machine' )) '-m' ,
68
- if (argResults['line-length' ] != null ) '-l ${argResults ['line-length' ]}' ,
69
- if (! boolArg ('dry-run' ) && ! boolArg ('machine' )) '-w' ,
70
- if (boolArg ('set-exit-if-changed' )) '--set-exit-if-changed' ,
43
+ dartBinary,
44
+ 'format' ,
71
45
...argResults.rest,
72
46
];
73
47
74
48
final int result = await processUtils.stream (command);
75
49
if (result != 0 ) {
76
- throwToolExit ('Formatting failed: $ result ' , exitCode: result);
50
+ throwToolExit ('' , exitCode: result);
77
51
}
78
-
79
52
return FlutterCommandResult .success ();
80
53
}
81
54
}
0 commit comments