| 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:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:utf'; | |
| 10 | 9 |
| 11 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
| 12 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 13 | 12 |
| 14 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; | 13 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; |
| 15 | 14 |
| 16 | 15 |
| 17 const BINARY_NAME = 'dartfmt'; | 16 const BINARY_NAME = 'dartfmt'; |
| 18 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false); | 17 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false); |
| 19 final argParser = _initArgParser(); | 18 final argParser = _initArgParser(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } catch (e) { | 102 } catch (e) { |
| 104 _log('Unable to format "${file.path}": $e'); | 103 _log('Unable to format "${file.path}": $e'); |
| 105 } | 104 } |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 | 107 |
| 109 _isDartFile(file) => dartFileRegExp.hasMatch(path.basename(file.path)); | 108 _isDartFile(file) => dartFileRegExp.hasMatch(path.basename(file.path)); |
| 110 | 109 |
| 111 _formatStdin(options) { | 110 _formatStdin(options) { |
| 112 var input = new StringBuffer(); | 111 var input = new StringBuffer(); |
| 113 stdin.transform(new Utf8DecoderTransformer()) | 112 stdin.transform(new Utf8Decoder()) |
| 114 .listen((data) => input.write(data), | 113 .listen((data) => input.write(data), |
| 115 onError: (error) => _log('Error reading from stdin'), | 114 onError: (error) => _log('Error reading from stdin'), |
| 116 onDone: () => print(_formatCU(input.toString()))); | 115 onDone: () => print(_formatCU(input.toString()))); |
| 117 } | 116 } |
| 118 | 117 |
| 119 /// Initialize the arg parser instance. | 118 /// Initialize the arg parser instance. |
| 120 ArgParser _initArgParser() { | 119 ArgParser _initArgParser() { |
| 121 // NOTE: these flags are placeholders only! | 120 // NOTE: these flags are placeholders only! |
| 122 var parser = new ArgParser(); | 121 var parser = new ArgParser(); |
| 123 parser.addFlag('write', abbr: 'w', negatable: false, | 122 parser.addFlag('write', abbr: 'w', negatable: false, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 'offset': formatResult.selection.offset, | 173 'offset': formatResult.selection.offset, |
| 175 'length': formatResult.selection.length | 174 'length': formatResult.selection.length |
| 176 } | 175 } |
| 177 }); | 176 }); |
| 178 | 177 |
| 179 /// Log the given [msg]. | 178 /// Log the given [msg]. |
| 180 _log(String msg) { | 179 _log(String msg) { |
| 181 //TODO(pquitslund): add proper log support | 180 //TODO(pquitslund): add proper log support |
| 182 print(msg); | 181 print(msg); |
| 183 } | 182 } |
| OLD | NEW |