Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: pkg/analyzer/bin/formatter.dart

Issue 189063006: add indent option to cmdline formatter (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/bin/formatter.dart
diff --git a/pkg/analyzer/bin/formatter.dart b/pkg/analyzer/bin/formatter.dart
index 400b309eff144d4f5e4a8aa19225ebe1e7fb9102..69674dbfbc333a1bbc65b55139fc405085490f60 100755
--- a/pkg/analyzer/bin/formatter.dart
+++ b/pkg/analyzer/bin/formatter.dart
@@ -34,6 +34,7 @@ const WRITE_FLAG = 'write';
const SELECTION_FLAG = 'selection';
const TRANSFORM_FLAG = 'transform';
const MAX_LINE_FLAG = 'max_line_length';
+const INDENT_FLAG = 'indent';
const FOLLOW_LINKS = false;
@@ -61,11 +62,29 @@ _readOptions(options) {
machineFormat = options[MACHINE_FLAG];
overwriteFileContents = options[WRITE_FLAG];
selection = _parseSelection(options[SELECTION_FLAG]);
- formatterSettings =
- new FormatterOptions(codeTransforms: options[TRANSFORM_FLAG],
- pageWidth: _parseLineLength(options[MAX_LINE_FLAG]));
+ formatterSettings = new FormatterOptions(
+ codeTransforms: options[TRANSFORM_FLAG],
+ tabsForIndent: _parseTabsForIndent(options[INDENT_FLAG]),
+ spacesPerIndent: _parseSpacesPerIndent(options[INDENT_FLAG]),
+ pageWidth: _parseLineLength(options[MAX_LINE_FLAG]));
}
+/// Translate the indent option into spaces per indent.
+int _parseSpacesPerIndent(String indentOption) {
+ if (indentOption == 'tab') {
+ return 1;
+ }
+ int spacesPerIndent = _toInt(indentOption);
+ if (spacesPerIndent == null) {
+ throw new FormatterException('Indentation is specified as an Integer or '
+ 'the value "tab".');
+ }
+ return spacesPerIndent;
+}
+
+/// Translate the indent option into tabs for indent.
+bool _parseTabsForIndent(String indentOption) => indentOption == 'tab';
+
CodeKind _parseKind(kindOption) {
switch(kindOption) {
case 'stmt' :
@@ -176,6 +195,9 @@ ArgParser _initArgParser() {
parser.addOption(MAX_LINE_FLAG, abbr: 'l', defaultsTo: '80',
help: 'Wrap lines longer than this length. '
'To never wrap, specify "Infinity" or "Inf" for short.');
+ parser.addOption(INDENT_FLAG, abbr: 'i', defaultsTo: '2',
+ help: 'Specify number of spaces per indentation. '
+ 'To indent using tabs, specify "--$INDENT_FLAG tab".');
pquitslund 2014/03/07 19:21:45 As discussed, let's make this option hidden. Also
danrubel 2014/03/11 14:22:36 Done.
parser.addOption(KIND_FLAG, abbr: 'k', defaultsTo: 'cu',
help: 'Specify source snippet kind ("stmt" or "cu") '
'--- [PROVISIONAL API].', hide: true);
« no previous file with comments | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698