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 | 9 |
10 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
11 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
12 | 12 |
13 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; | 13 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; |
14 | 14 |
15 | 15 |
16 const BINARY_NAME = 'dartfmt'; | 16 const BINARY_NAME = 'dartfmt'; |
17 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false); | 17 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false); |
18 final argParser = _initArgParser(); | 18 final argParser = _initArgParser(); |
19 final defaultSelection = new Selection(-1, -1); | 19 final defaultSelection = new Selection(-1, -1); |
20 | 20 |
21 var formatterSettings; | 21 var formatterSettings; |
22 | 22 |
23 bool machineFormat; | 23 bool machineFormat; |
24 bool overwriteFileContents; | 24 bool overwriteFileContents; |
25 Selection selection; | 25 Selection selection; |
26 const followLinks = false; | 26 const followLinks = false; |
27 | 27 |
28 | 28 |
29 main() { | 29 main(args) { |
30 var options = argParser.parse(new Options().arguments); | 30 var options = argParser.parse(args); |
31 if (options['help']) { | 31 if (options['help']) { |
32 _printUsage(); | 32 _printUsage(); |
33 return; | 33 return; |
34 } | 34 } |
35 | 35 |
36 _readOptions(options); | 36 _readOptions(options); |
37 | 37 |
38 if (options.rest.isEmpty) { | 38 if (options.rest.isEmpty) { |
39 _formatStdin(options); | 39 _formatStdin(options); |
40 } else { | 40 } else { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 'offset': formatResult.selection.offset, | 173 'offset': formatResult.selection.offset, |
174 'length': formatResult.selection.length | 174 'length': formatResult.selection.length |
175 } | 175 } |
176 }); | 176 }); |
177 | 177 |
178 /// Log the given [msg]. | 178 /// Log the given [msg]. |
179 _log(String msg) { | 179 _log(String msg) { |
180 //TODO(pquitslund): add proper log support | 180 //TODO(pquitslund): add proper log support |
181 print(msg); | 181 print(msg); |
182 } | 182 } |
OLD | NEW |