OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 /// Reformats the status file(s) at the given path. |
| 6 import 'dart:io'; |
| 7 |
| 8 import 'package:status_file/status_file.dart'; |
| 9 |
| 10 void main(List<String> arguments) { |
| 11 if (arguments.length != 1) { |
| 12 print("Usage: dart status_file/bin/format.dart <path>"); |
| 13 exit(1); |
| 14 } |
| 15 |
| 16 var path = arguments[0]; |
| 17 |
| 18 if (new File(path).existsSync()) { |
| 19 formatFile(path); |
| 20 } else if (new Directory(path).existsSync()) { |
| 21 for (var entry in new Directory(path).listSync(recursive: true)) { |
| 22 if (!entry.path.endsWith(".status")) continue; |
| 23 |
| 24 formatFile(entry.path); |
| 25 } |
| 26 } |
| 27 } |
| 28 |
| 29 void formatFile(String path) { |
| 30 try { |
| 31 var statusFile = new StatusFile.read(path); |
| 32 new File(path).writeAsStringSync(statusFile.serialize()); |
| 33 print("Formatted $path"); |
| 34 } on SyntaxError catch (error) { |
| 35 stderr.writeln("Could not parse $path:\n$error"); |
| 36 } |
| 37 } |
OLD | NEW |