Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: pkg/analyzer_experimental/bin/formatter.dart

Issue 23534016: Formatter main overwrite flag fix. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_experimental/bin/formatter.dart
===================================================================
--- pkg/analyzer_experimental/bin/formatter.dart (revision 26815)
+++ pkg/analyzer_experimental/bin/formatter.dart (working copy)
@@ -16,12 +16,16 @@
final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false);
final argParser = _initArgParser();
+bool overwriteFileContents;
+
void main() {
var options = argParser.parse(new Options().arguments);
if (options['help']) {
_printUsage();
return;
}
+ overwriteFileContents = options['write'];
+
if (options.rest.isEmpty) {
_formatStdin(options);
} else {
@@ -50,15 +54,17 @@
_formatDirectory(dir) =>
dir.listSync().forEach((resource) => _formatResource(resource));
-
void _formatFile(file) {
if (_isDartFile(file)) {
try {
var buffer = new StringBuffer();
var rawSource = file.readAsStringSync();
var formatted = _formatCU(rawSource);
- print(formatted);
- file.writeAsStringSync(formatted);
+ if (overwriteFileContents) {
+ file.writeAsStringSync(formatted);
+ } else {
+ print(formatted);
+ }
} catch (e) {
_log('Error formatting "${file.path}": $e');
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698