mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Add a version
workflow to arcanist.
Summary: A `version` workflow would be useful, especially for less technical users. Additionally, whenever I am faced with a new command I reasonably expect `$CMD [--help|help]` and `$CMD [--version|version]` to work. Test Plan: Ran `arc version`. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9265
This commit is contained in:
parent
0d0b8abcdd
commit
b7bb6c8348
2 changed files with 63 additions and 0 deletions
|
@ -174,6 +174,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistUploadWorkflow' => 'workflow/ArcanistUploadWorkflow.php',
|
||||
'ArcanistUsageException' => 'exception/ArcanistUsageException.php',
|
||||
'ArcanistUserAbortException' => 'exception/usage/ArcanistUserAbortException.php',
|
||||
'ArcanistVersionWorkflow' => 'workflow/ArcanistVersionWorkflow.php',
|
||||
'ArcanistWhichWorkflow' => 'workflow/ArcanistWhichWorkflow.php',
|
||||
'ArcanistWorkingCopyIdentity' => 'workingcopyidentity/ArcanistWorkingCopyIdentity.php',
|
||||
'ArcanistXHPASTLintNamingHook' => 'lint/linter/xhpast/ArcanistXHPASTLintNamingHook.php',
|
||||
|
@ -337,6 +338,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistUploadWorkflow' => 'ArcanistBaseWorkflow',
|
||||
'ArcanistUsageException' => 'Exception',
|
||||
'ArcanistUserAbortException' => 'ArcanistUsageException',
|
||||
'ArcanistVersionWorkflow' => 'ArcanistBaseWorkflow',
|
||||
'ArcanistWhichWorkflow' => 'ArcanistBaseWorkflow',
|
||||
'ArcanistXHPASTLintNamingHookTestCase' => 'ArcanistTestCase',
|
||||
'ArcanistXHPASTLintTestSwitchHook' => 'ArcanistXHPASTLintSwitchHook',
|
||||
|
|
61
src/workflow/ArcanistVersionWorkflow.php
Normal file
61
src/workflow/ArcanistVersionWorkflow.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Display the current version of Arcanist.
|
||||
*/
|
||||
final class ArcanistVersionWorkflow extends ArcanistBaseWorkflow {
|
||||
|
||||
public function getWorkflowName() {
|
||||
return 'version';
|
||||
}
|
||||
|
||||
public function getCommandSynopses() {
|
||||
return phutil_console_format(<<<EOTEXT
|
||||
**version** [__options__]
|
||||
EOTEXT
|
||||
);
|
||||
}
|
||||
|
||||
public function getCommandHelp() {
|
||||
return phutil_console_format(pht(<<<EOTEXT
|
||||
Supports: cli
|
||||
Shows the current version of arcanist.
|
||||
EOTEXT
|
||||
));
|
||||
}
|
||||
|
||||
public function run() {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
if (!Filesystem::binaryExists('git')) {
|
||||
throw new ArcanistUsageException(
|
||||
'Cannot display current version without having `git` installed.');
|
||||
}
|
||||
|
||||
$roots = array(
|
||||
'arcanist' => dirname(phutil_get_library_root('arcanist')),
|
||||
'libphutil' => dirname(phutil_get_library_root('phutil')),
|
||||
);
|
||||
|
||||
foreach ($roots as $lib => $root) {
|
||||
$working_copy = ArcanistWorkingCopyIdentity::newFromPath($root);
|
||||
$configuration_manager = clone $this->getConfigurationManager();
|
||||
$configuration_manager->setWorkingCopyIdentity($working_copy);
|
||||
$repository = ArcanistRepositoryAPI::newAPIFromConfigurationManager(
|
||||
$configuration_manager);
|
||||
|
||||
if (!Filesystem::pathExists($repository->getMetadataPath())) {
|
||||
throw new ArcanistUsageException("{$lib} is not a git working copy.");
|
||||
}
|
||||
|
||||
list($stdout) = $repository->execxLocal('log -1 --format=%s', '%H %ct');
|
||||
list($commit, $timestamp) = explode(' ', $stdout);
|
||||
|
||||
$console->writeOut("%s %s (%s)\n",
|
||||
$lib,
|
||||
$commit,
|
||||
date('j M Y', (int)$timestamp));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue