Commit f1963243 authored by Adam Barth's avatar Adam Barth

Merge pull request #420 from abarth/version

Add a --version option to flutter
parents 6f0464c0 9e212017
...@@ -33,6 +33,9 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -33,6 +33,9 @@ class FlutterCommandRunner extends CommandRunner {
negatable: false, negatable: false,
help: 'Very noisy logging, including the output of all ' help: 'Very noisy logging, including the output of all '
'shell commands executed.'); 'shell commands executed.');
argParser.addFlag('version',
negatable: false,
help: 'Reports the version of this tool.');
String packagesHelp; String packagesHelp;
if (ArtifactStore.isPackageRootValid) if (ArtifactStore.isPackageRootValid)
packagesHelp = '\n(defaults to "${ArtifactStore.packageRoot}")'; packagesHelp = '\n(defaults to "${ArtifactStore.packageRoot}")';
...@@ -138,6 +141,14 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -138,6 +141,14 @@ class FlutterCommandRunner extends CommandRunner {
if (globalResults.wasParsed('package-root')) if (globalResults.wasParsed('package-root'))
ArtifactStore.packageRoot = globalResults['package-root']; ArtifactStore.packageRoot = globalResults['package-root'];
if (globalResults['version']) {
String revision = runSync([
'git', 'rev-parse', 'HEAD'
], workingDirectory: ArtifactStore.flutterRoot).trim();
print('flutter version $revision');
return new Future<int>.value(0);
}
return super.runCommand(globalResults); return super.runCommand(globalResults);
} }
......
...@@ -64,11 +64,12 @@ Future<Process> runDetached(List<String> cmd) { ...@@ -64,11 +64,12 @@ Future<Process> runDetached(List<String> cmd) {
/// Run cmd and return stdout. /// Run cmd and return stdout.
/// Throws an error if cmd exits with a non-zero value. /// Throws an error if cmd exits with a non-zero value.
String runCheckedSync(List<String> cmd) => String runCheckedSync(List<String> cmd, { String workingDirectory }) =>
_runWithLoggingSync(cmd, checked: true); _runWithLoggingSync(cmd, workingDirectory: workingDirectory, checked: true);
/// Run cmd and return stdout. /// Run cmd and return stdout.
String runSync(List<String> cmd) => _runWithLoggingSync(cmd); String runSync(List<String> cmd, { String workingDirectory }) =>
_runWithLoggingSync(cmd, workingDirectory: workingDirectory);
/// Return the platform specific name for the given Dart SDK binary. So, `pub` /// Return the platform specific name for the given Dart SDK binary. So, `pub`
/// ==> `pub.bat`. /// ==> `pub.bat`.
...@@ -76,10 +77,13 @@ String sdkBinaryName(String name) { ...@@ -76,10 +77,13 @@ String sdkBinaryName(String name) {
return Platform.isWindows ? '$name.bat' : name; return Platform.isWindows ? '$name.bat' : name;
} }
String _runWithLoggingSync(List<String> cmd, {bool checked: false}) { String _runWithLoggingSync(List<String> cmd, {
bool checked: false,
String workingDirectory
}) {
_logging.info(cmd.join(' ')); _logging.info(cmd.join(' '));
ProcessResult results = ProcessResult results =
Process.runSync(cmd[0], cmd.getRange(1, cmd.length).toList()); Process.runSync(cmd[0], cmd.getRange(1, cmd.length).toList(), workingDirectory: workingDirectory);
if (results.exitCode != 0) { if (results.exitCode != 0) {
String errorDescription = 'Error code ${results.exitCode} ' String errorDescription = 'Error code ${results.exitCode} '
'returned when attempting to run command: ${cmd.join(' ')}'; 'returned when attempting to run command: ${cmd.join(' ')}';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment