~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/workflow/ArcanistVersionWorkflow.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Display the current version of Arcanist.
 
5
 */
 
6
final class ArcanistVersionWorkflow extends ArcanistWorkflow {
 
7
 
 
8
  public function getWorkflowName() {
 
9
    return 'version';
 
10
  }
 
11
 
 
12
  public function getCommandSynopses() {
 
13
    return phutil_console_format(<<<EOTEXT
 
14
      **version** [__options__]
 
15
EOTEXT
 
16
      );
 
17
  }
 
18
 
 
19
  public function getCommandHelp() {
 
20
    return phutil_console_format(pht(<<<EOTEXT
 
21
          Supports: cli
 
22
          Shows the current version of arcanist.
 
23
EOTEXT
 
24
      ));
 
25
  }
 
26
 
 
27
  public function run() {
 
28
    $console = PhutilConsole::getConsole();
 
29
 
 
30
    if (!Filesystem::binaryExists('git')) {
 
31
      throw new ArcanistUsageException(
 
32
        'Cannot display current version without having `git` installed.');
 
33
    }
 
34
 
 
35
    $roots = array(
 
36
      'arcanist' => dirname(phutil_get_library_root('arcanist')),
 
37
      'libphutil' => dirname(phutil_get_library_root('phutil')),
 
38
    );
 
39
 
 
40
    foreach ($roots as $lib => $root) {
 
41
      $working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
 
42
      $configuration_manager = clone $this->getConfigurationManager();
 
43
      $configuration_manager->setWorkingCopyIdentity($working_copy);
 
44
      $repository = ArcanistRepositoryAPI::newAPIFromConfigurationManager(
 
45
        $configuration_manager);
 
46
 
 
47
      if (!Filesystem::pathExists($repository->getMetadataPath())) {
 
48
        throw new ArcanistUsageException("{$lib} is not a git working copy.");
 
49
      }
 
50
 
 
51
      list($stdout) = $repository->execxLocal('log -1 --format=%s', '%H %ct');
 
52
      list($commit, $timestamp) = explode(' ', $stdout);
 
53
 
 
54
      $console->writeOut("%s %s (%s)\n",
 
55
        $lib,
 
56
        $commit,
 
57
        date('j M Y', (int)$timestamp));
 
58
    }
 
59
  }
 
60
 
 
61
}