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

Unified Diff: lib/src/executable.dart

Issue 1053113004: Support a --version flag. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: CHANGELOG Created 5 years, 8 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 | « CHANGELOG.md ('k') | test/runner/runner_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/executable.dart
diff --git a/lib/src/executable.dart b/lib/src/executable.dart
index aad1fcd6310a86e7be05ea0110b388ae116df0c7..e774dc43f545816de81ac4ec01c8989ab3d575bb 100644
--- a/lib/src/executable.dart
+++ b/lib/src/executable.dart
@@ -74,6 +74,8 @@ bool get _usesTransformer {
void main(List<String> args) {
_parser.addFlag("help", abbr: "h", negatable: false,
help: "Shows this usage information.");
+ _parser.addFlag("version", negatable: false,
+ help: "Shows the package's version.");
_parser.addOption("package-root", hide: true);
_parser.addOption("name",
abbr: 'n',
@@ -114,6 +116,14 @@ void main(List<String> args) {
return;
}
+ if (options["version"]) {
+ if (!_printVersion()) {
+ stderr.writeln("Couldn't find version number.");
+ exitCode = exit_codes.data;
+ }
+ return;
+ }
+
var color = options["color"];
if (color == null) color = canUseSpecialChars;
@@ -292,3 +302,61 @@ Usage: pub run test:test [files or directories...]
${_parser.usage}
""");
}
+
+/// Prints the version number of the test package.
+///
+/// This loads the version number from the current package's lockfile. It
+/// returns true if it successfully printed the version number and false if it
+/// couldn't be loaded.
+bool _printVersion() {
+ var lockfile;
+ try {
+ lockfile = loadYaml(new File("pubspec.lock").readAsStringSync());
+ } on FormatException catch (_) {
+ return false;
+ } on IOException catch (_) {
+ return false;
+ }
+
+ if (lockfile is! Map) return false;
+ var packages = lockfile["packages"];
+ if (packages is! Map) return false;
+ var package = packages["test"];
+ if (package is! Map) return false;
+
+ var source = package["source"];
+ if (source is! String) return false;
+
+ switch (source) {
+ case "hosted":
+ var version = package["version"];
+ if (version is! String) return false;
+
+ print(version);
+ return true;
+
+ case "git":
+ var version = package["version"];
+ if (version is! String) return false;
+ var description = package["description"];
+ if (description is! Map) return false;
+ var ref = description["resolved-ref"];
+ if (ref is! String) return false;
+
+ print("$version (${ref.substring(0, 7)})");
+ return true;
+
+ case "path":
+ var version = package["version"];
+ if (version is! String) return false;
+ var description = package["description"];
+ if (description is! Map) return false;
+ var path = description["path"];
+ if (path is! String) return false;
+
+ print("$version (from $path)");
+ return true;
+
+ default: return false;
+ }
+}
« no previous file with comments | « CHANGELOG.md ('k') | test/runner/runner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698