| 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'; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 /// Initialize the arg parser instance. | 129 /// Initialize the arg parser instance. |
| 130 ArgParser _initArgParser() { | 130 ArgParser _initArgParser() { |
| 131 // NOTE: these flags are placeholders only! | 131 // NOTE: these flags are placeholders only! |
| 132 var parser = new ArgParser(); | 132 var parser = new ArgParser(); |
| 133 parser.addFlag('write', abbr: 'w', negatable: false, | 133 parser.addFlag('write', abbr: 'w', negatable: false, |
| 134 help: 'Write reformatted sources to files (overwriting contents). ' | 134 help: 'Write reformatted sources to files (overwriting contents). ' |
| 135 'Do not print reformatted sources to standard output.'); | 135 'Do not print reformatted sources to standard output.'); |
| 136 parser.addOption('kind', abbr: 'k', defaultsTo: 'cu', | 136 parser.addOption('kind', abbr: 'k', defaultsTo: 'cu', |
| 137 help: 'Specify source snippet kind ("stmt" or "cu")' | 137 help: 'Specify source snippet kind ("stmt" or "cu")' |
| 138 ' --- [PROVISIONAL API].'); | 138 ' --- [PROVISIONAL API].', hide: true); |
| 139 parser.addFlag('machine', abbr: 'm', negatable: false, | 139 parser.addFlag('machine', abbr: 'm', negatable: false, |
| 140 help: 'Produce output in a format suitable for parsing.'); | 140 help: 'Produce output in a format suitable for parsing.'); |
| 141 parser.addOption('selection', abbr: 's', | 141 parser.addOption('selection', abbr: 's', |
| 142 help: 'Specify selection information as an offset,length pair ' | 142 help: 'Specify selection information as an offset,length pair ' |
| 143 '(e.g., -s "0,4").'); | 143 '(e.g., -s "0,4").', hide: true); |
| 144 parser.addFlag('transform', abbr: 't', negatable: true, | 144 parser.addFlag('transform', abbr: 't', negatable: true, |
| 145 help: 'Perform code transformations.'); | 145 help: 'Perform code transformations.'); |
| 146 parser.addFlag('help', abbr: 'h', negatable: false, | 146 parser.addFlag('help', abbr: 'h', negatable: false, |
| 147 help: 'Print this usage information.'); | 147 help: 'Print this usage information.'); |
| 148 return parser; | 148 return parser; |
| 149 } | 149 } |
| 150 | 150 |
| 151 | 151 |
| 152 /// Displays usage information. | 152 /// Displays usage information. |
| 153 _printUsage() { | 153 _printUsage() { |
| 154 var buffer = new StringBuffer(); | 154 var buffer = new StringBuffer(); |
| 155 buffer..write('$BINARY_NAME formats Dart programs.') | 155 buffer..write('$BINARY_NAME formats Dart programs.') |
| 156 ..write('\n\n') | 156 ..write('\n\n') |
| 157 ..write('Without an explicit path, $BINARY_NAME processes the standard ' | 157 ..write('Without an explicit path, $BINARY_NAME processes the standard ' |
| 158 'input. Given a file, it operates on that file; given a ' | 158 'input. Given a file, it operates on that file; given a ' |
| 159 'directory, it operates on all .dart files in that directory, ' | 159 'directory, it operates on all .dart files in that directory, ' |
| 160 'recursively. (Files starting with a period are ignored.) By ' | 160 'recursively. (Files starting with a period are ignored.) By ' |
| 161 'default, $BINARY_NAME prints the reformatted sources to ' | 161 'default, $BINARY_NAME prints the reformatted sources to ' |
| 162 'standard output.') | 162 'standard output.') |
| 163 ..write('\n\n') | 163 ..write('\n\n') |
| 164 ..write('Supported flags are:') | |
| 165 ..write('Usage: $BINARY_NAME [flags] [path...]\n\n') | 164 ..write('Usage: $BINARY_NAME [flags] [path...]\n\n') |
| 165 ..write('Supported flags are:\n') |
| 166 ..write('${argParser.getUsage()}\n\n'); | 166 ..write('${argParser.getUsage()}\n\n'); |
| 167 _log(buffer.toString()); | 167 _log(buffer.toString()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 /// Format this [src], treating it as the given snippet [kind]. | 170 /// Format this [src], treating it as the given snippet [kind]. |
| 171 String _format(src, kind) { | 171 String _format(src, kind) { |
| 172 var formatResult = new CodeFormatter(formatterSettings).format( | 172 var formatResult = new CodeFormatter(formatterSettings).format( |
| 173 kind, src, selection: selection); | 173 kind, src, selection: selection); |
| 174 if (machineFormat) { | 174 if (machineFormat) { |
| 175 if (formatResult.selection == null) { | 175 if (formatResult.selection == null) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 'offset': formatResult.selection.offset, | 187 'offset': formatResult.selection.offset, |
| 188 'length': formatResult.selection.length | 188 'length': formatResult.selection.length |
| 189 } | 189 } |
| 190 }); | 190 }); |
| 191 | 191 |
| 192 /// Log the given [msg]. | 192 /// Log the given [msg]. |
| 193 _log(String msg) { | 193 _log(String msg) { |
| 194 //TODO(pquitslund): add proper log support | 194 //TODO(pquitslund): add proper log support |
| 195 print(msg); | 195 print(msg); |
| 196 } | 196 } |
| OLD | NEW |