From b7bb6c834830e5ea413323284e1b71663fdaa19e Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Fri, 23 May 2014 19:35:33 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + src/workflow/ArcanistVersionWorkflow.php | 61 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/workflow/ArcanistVersionWorkflow.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8ad2b8a4..ba7adb4c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/workflow/ArcanistVersionWorkflow.php b/src/workflow/ArcanistVersionWorkflow.php new file mode 100644 index 00000000..65e54b45 --- /dev/null +++ b/src/workflow/ArcanistVersionWorkflow.php @@ -0,0 +1,61 @@ + 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)); + } + } + +}