diff --git a/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart b/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart index 295e52cf39..dc23c0c04d 100644 --- a/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/commands/flutter_command_runner.dart @@ -33,6 +33,9 @@ class FlutterCommandRunner extends CommandRunner { negatable: false, help: 'Very noisy logging, including the output of all ' 'shell commands executed.'); + argParser.addFlag('version', + negatable: false, + help: 'Reports the version of this tool.'); String packagesHelp; if (ArtifactStore.isPackageRootValid) packagesHelp = '\n(defaults to "${ArtifactStore.packageRoot}")'; @@ -138,6 +141,14 @@ class FlutterCommandRunner extends CommandRunner { if (globalResults.wasParsed('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.value(0); + } + return super.runCommand(globalResults); } diff --git a/packages/flutter_tools/lib/src/process.dart b/packages/flutter_tools/lib/src/process.dart index c0a547ff80..219a020c1f 100644 --- a/packages/flutter_tools/lib/src/process.dart +++ b/packages/flutter_tools/lib/src/process.dart @@ -64,11 +64,12 @@ Future runDetached(List cmd) { /// Run cmd and return stdout. /// Throws an error if cmd exits with a non-zero value. -String runCheckedSync(List cmd) => - _runWithLoggingSync(cmd, checked: true); +String runCheckedSync(List cmd, { String workingDirectory }) => + _runWithLoggingSync(cmd, workingDirectory: workingDirectory, checked: true); /// Run cmd and return stdout. -String runSync(List cmd) => _runWithLoggingSync(cmd); +String runSync(List cmd, { String workingDirectory }) => + _runWithLoggingSync(cmd, workingDirectory: workingDirectory); /// Return the platform specific name for the given Dart SDK binary. So, `pub` /// ==> `pub.bat`. @@ -76,10 +77,13 @@ String sdkBinaryName(String name) { return Platform.isWindows ? '$name.bat' : name; } -String _runWithLoggingSync(List cmd, {bool checked: false}) { +String _runWithLoggingSync(List cmd, { + bool checked: false, + String workingDirectory +}) { _logging.info(cmd.join(' ')); 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) { String errorDescription = 'Error code ${results.exitCode} ' 'returned when attempting to run command: ${cmd.join(' ')}';