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

Unified Diff: bin/format.dart

Issue 1470263004: Add "-i" to command line to specify leading indent. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years, 1 month 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 | lib/src/formatter_options.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/format.dart
diff --git a/bin/format.dart b/bin/format.dart
index 9df6265bef6103773ab8f745a18fc9afda668fac..8867f184d04d3e338e17a6d702e33d6900317950 100644
--- a/bin/format.dart
+++ b/bin/format.dart
@@ -25,6 +25,8 @@ void main(List<String> args) {
negatable: false, help: "Shows version information.");
parser.addOption("line-length",
abbr: "l", help: "Wrap lines longer than this.", defaultsTo: "80");
+ parser.addOption("indent",
+ abbr: "i", help: "Spaces of leading indentation.", defaultsTo: "0");
parser.addOption("preserve",
help: 'Selection to preserve, formatted as "start:length".');
parser.addFlag("dry-run",
@@ -118,7 +120,6 @@ void main(List<String> args) {
}
var pageWidth;
-
try {
pageWidth = int.parse(argResults["line-length"]);
} on FormatException catch (_) {
@@ -128,10 +129,22 @@ void main(List<String> args) {
'"${argResults['line-length']}".');
}
+ var indent;
+
+ try {
+ indent = int.parse(argResults["indent"]);
+ if (indent < 0 || indent.toInt() != indent) throw new FormatException();
+ } on FormatException catch (_) {
+ usageError(
+ parser,
+ '--indent must be a non-negative integer, was '
+ '"${argResults['indent']}".');
+ }
+
var followLinks = argResults["follow-links"];
var options = new FormatterOptions(reporter,
- pageWidth: pageWidth, followLinks: followLinks);
+ indent: indent, pageWidth: pageWidth, followLinks: followLinks);
if (argResults.rest.isEmpty) {
formatStdin(options, selection);
@@ -168,7 +181,8 @@ void formatStdin(FormatterOptions options, List<int> selection) {
var input = new StringBuffer();
stdin.transform(new Utf8Decoder()).listen(input.write, onDone: () {
- var formatter = new DartFormatter(pageWidth: options.pageWidth);
+ var formatter =
+ new DartFormatter(indent: options.indent, pageWidth: options.pageWidth);
try {
options.reporter.beforeFile(null, "<stdin>");
var source = new SourceCode(input.toString(),
« no previous file with comments | « no previous file | lib/src/formatter_options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698