forked from firka/flutter
Add a --version option to flutter
This option just prints the current git revision. Fixes #40
This commit is contained in:
@@ -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<int>.value(0);
|
||||
}
|
||||
|
||||
return super.runCommand(globalResults);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,11 +64,12 @@ Future<Process> runDetached(List<String> cmd) {
|
||||
|
||||
/// Run cmd and return stdout.
|
||||
/// Throws an error if cmd exits with a non-zero value.
|
||||
String runCheckedSync(List<String> cmd) =>
|
||||
_runWithLoggingSync(cmd, checked: true);
|
||||
String runCheckedSync(List<String> cmd, { String workingDirectory }) =>
|
||||
_runWithLoggingSync(cmd, workingDirectory: workingDirectory, checked: true);
|
||||
|
||||
/// 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`
|
||||
/// ==> `pub.bat`.
|
||||
@@ -76,10 +77,13 @@ String sdkBinaryName(String 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(' '));
|
||||
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(' ')}';
|
||||
|
||||
Reference in New Issue
Block a user