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

Unified Diff: packages/dart_style/bin/format.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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 | « packages/dart_style/README.md ('k') | packages/dart_style/codereview.settings » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/dart_style/bin/format.dart
diff --git a/packages/dart_style/bin/format.dart b/packages/dart_style/bin/format.dart
index cd97fb01593f259708cebd06f10f400b55d5585a..8d179c19a0537fdc34f5c8c1213c35de21513bde 100644
--- a/packages/dart_style/bin/format.dart
+++ b/packages/dart_style/bin/format.dart
@@ -6,19 +6,27 @@ import 'dart:convert';
import 'dart:io';
import 'package:args/args.dart';
+
import 'package:dart_style/src/dart_formatter.dart';
import 'package:dart_style/src/formatter_exception.dart';
import 'package:dart_style/src/formatter_options.dart';
import 'package:dart_style/src/io.dart';
import 'package:dart_style/src/source_code.dart';
+// Note: The following line of code is modified by tool/grind.dart.
+const version = "0.2.1";
+
void main(List<String> args) {
var parser = new ArgParser(allowTrailingOptions: true);
parser.addFlag("help",
abbr: "h", negatable: false, help: "Shows usage information.");
+ parser.addFlag("version",
+ 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",
@@ -33,6 +41,8 @@ void main(List<String> args) {
abbr: "m",
negatable: false,
help: "Produce machine-readable JSON output.");
+ parser.addFlag("profile",
+ negatable: false, help: "Display profile times after running.");
parser.addFlag("follow-links",
negatable: false,
help: "Follow links to files and directories.\n"
@@ -54,6 +64,11 @@ void main(List<String> args) {
return;
}
+ if (argResults["version"]) {
+ print(version);
+ return;
+ }
+
// Can only preserve a selection when parsing from stdin.
var selection;
@@ -100,8 +115,11 @@ void main(List<String> args) {
reporter = OutputReporter.printJson;
}
- var pageWidth;
+ if (argResults["profile"]) {
+ reporter = new ProfileReporter(reporter);
+ }
+ var pageWidth;
try {
pageWidth = int.parse(argResults["line-length"]);
} on FormatException catch (_) {
@@ -111,16 +129,32 @@ 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);
} else {
formatPaths(options, argResults.rest);
}
+
+ if (argResults["profile"]) {
+ (reporter as ProfileReporter).showProfile();
+ }
}
List<int> parseSelection(String selection) {
@@ -147,15 +181,17 @@ 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(),
uri: "stdin",
selectionStart: selectionStart,
selectionLength: selectionLength);
var output = formatter.formatSource(source);
options.reporter
- .showFile(null, "<stdin>", output, changed: source != output);
+ .afterFile(null, "<stdin>", output, changed: source != output);
return true;
} on FormatterException catch (err) {
stderr.writeln(err.message());
« no previous file with comments | « packages/dart_style/README.md ('k') | packages/dart_style/codereview.settings » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698