OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 | 9 |
10 import 'package:dart_style/src/dart_formatter.dart'; | 10 import 'package:dart_style/src/dart_formatter.dart'; |
(...skipping 15 matching lines...) Expand all Loading... |
26 parser.addOption("line-length", | 26 parser.addOption("line-length", |
27 abbr: "l", help: "Wrap lines longer than this.", defaultsTo: "80"); | 27 abbr: "l", help: "Wrap lines longer than this.", defaultsTo: "80"); |
28 parser.addOption("indent", | 28 parser.addOption("indent", |
29 abbr: "i", help: "Spaces of leading indentation.", defaultsTo: "0"); | 29 abbr: "i", help: "Spaces of leading indentation.", defaultsTo: "0"); |
30 parser.addOption("preserve", | 30 parser.addOption("preserve", |
31 help: 'Selection to preserve, formatted as "start:length".'); | 31 help: 'Selection to preserve, formatted as "start:length".'); |
32 parser.addFlag("dry-run", | 32 parser.addFlag("dry-run", |
33 abbr: "n", | 33 abbr: "n", |
34 negatable: false, | 34 negatable: false, |
35 help: "Show which files would be modified but make no changes."); | 35 help: "Show which files would be modified but make no changes."); |
| 36 parser.addFlag("set-exit-if-changed", |
| 37 negatable: false, |
| 38 help: "Return exit code 1 if there are any formatting changes."); |
36 parser.addFlag("overwrite", | 39 parser.addFlag("overwrite", |
37 abbr: "w", | 40 abbr: "w", |
38 negatable: false, | 41 negatable: false, |
39 help: "Overwrite input files with formatted output."); | 42 help: "Overwrite input files with formatted output."); |
40 parser.addFlag("machine", | 43 parser.addFlag("machine", |
41 abbr: "m", | 44 abbr: "m", |
42 negatable: false, | 45 negatable: false, |
43 help: "Produce machine-readable JSON output."); | 46 help: "Produce machine-readable JSON output."); |
44 parser.addFlag("profile", | 47 parser.addFlag("profile", |
45 negatable: false, help: "Display profile times after running."); | 48 negatable: false, help: "Display profile times after running."); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 115 |
113 reporter = OutputReporter.overwrite; | 116 reporter = OutputReporter.overwrite; |
114 } else if (argResults["machine"]) { | 117 } else if (argResults["machine"]) { |
115 reporter = OutputReporter.printJson; | 118 reporter = OutputReporter.printJson; |
116 } | 119 } |
117 | 120 |
118 if (argResults["profile"]) { | 121 if (argResults["profile"]) { |
119 reporter = new ProfileReporter(reporter); | 122 reporter = new ProfileReporter(reporter); |
120 } | 123 } |
121 | 124 |
| 125 if (argResults["set-exit-if-changed"]) { |
| 126 reporter = new SetExitReporter(reporter); |
| 127 } |
| 128 |
122 var pageWidth; | 129 var pageWidth; |
123 try { | 130 try { |
124 pageWidth = int.parse(argResults["line-length"]); | 131 pageWidth = int.parse(argResults["line-length"]); |
125 } on FormatException catch (_) { | 132 } on FormatException catch (_) { |
126 usageError( | 133 usageError( |
127 parser, | 134 parser, |
128 '--line-length must be an integer, was ' | 135 '--line-length must be an integer, was ' |
129 '"${argResults['line-length']}".'); | 136 '"${argResults['line-length']}".'); |
130 } | 137 } |
131 | 138 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 output = stdout; | 250 output = stdout; |
244 } | 251 } |
245 | 252 |
246 output.write("""$message | 253 output.write("""$message |
247 | 254 |
248 Usage: dartfmt [-n|-w] [files or directories...] | 255 Usage: dartfmt [-n|-w] [files or directories...] |
249 | 256 |
250 ${parser.usage} | 257 ${parser.usage} |
251 """); | 258 """); |
252 } | 259 } |
OLD | NEW |