| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 | 2 |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 _formatFiles(files) { | 30 _formatFiles(files) { |
| 31 for (var file in files) { | 31 for (var file in files) { |
| 32 _formatFile(file); | 32 _formatFile(file); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 _formatFile(path) { | 36 _formatFile(path) { |
| 37 var buffer = new StringBuffer(); | 37 var buffer = new StringBuffer(); |
| 38 var file = new File(path); | 38 var file = new File(path); |
| 39 file.openRead() | 39 file.openRead() |
| 40 .transform(new StringDecoder()) | 40 .transform(UTF8.decoder) |
| 41 .listen((data) => buffer.write(data), | 41 .listen((data) => buffer.write(data), |
| 42 onError: (error) => print('Error, could not open "$path"'), | 42 onError: (error) => print('Error, could not open "$path"'), |
| 43 onDone: () => print(_formatCU(buffer.toString()))); | 43 onDone: () => print(_formatCU(buffer.toString()))); |
| 44 } | 44 } |
| 45 | 45 |
| 46 _formatStdin(options) { | 46 _formatStdin(options) { |
| 47 _log('not supported yet!'); | 47 _log('not supported yet!'); |
| 48 // stdin.transform(new StringDecoder()) | 48 // stdin.transform(new StringDecoder()) |
| 49 // .listen((String data) => print(data), | 49 // .listen((String data) => print(data), |
| 50 // onError: (error) => print('Error reading from stdin'), | 50 // onError: (error) => print('Error reading from stdin'), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 /// Format the given [src] as a compilation unit. | 85 /// Format the given [src] as a compilation unit. |
| 86 String _formatCU(src, {options: const FormatterOptions()}) => | 86 String _formatCU(src, {options: const FormatterOptions()}) => |
| 87 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); | 87 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); |
| 88 | 88 |
| 89 /// Log the given [msg]. | 89 /// Log the given [msg]. |
| 90 _log(String msg) { | 90 _log(String msg) { |
| 91 //TODO(pquitslund): add proper log support | 91 //TODO(pquitslund): add proper log support |
| 92 print(msg); | 92 print(msg); |
| 93 } | 93 } |
| OLD | NEW |