1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Make Arcanist workflow names explicit

Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.

Remove all the rules tying workflow names to class names through arcane incantations.

This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).

Test Plan: Ran "arc help", "arc which", "arc diff", etc.

Reviewers: edward, vrana, btrahan

Reviewed By: edward

CC: aran, zeeg

Differential Revision: https://secure.phabricator.com/D3691
This commit is contained in:
epriestley 2012-10-17 08:35:03 -07:00
parent 2d269aefed
commit 4c476c0201
36 changed files with 157 additions and 44 deletions

View file

@ -45,53 +45,29 @@ class ArcanistConfiguration {
$command = 'help';
}
if ($command == 'base') {
return null;
}
$workflow_class = 'Arcanist'.ucfirst($command).'Workflow';
$workflow_class = preg_replace_callback(
'/-([a-z])/',
array(
'ArcanistConfiguration',
'replaceClassnameHyphens',
),
$workflow_class);
$symbols = id(new PhutilSymbolLoader())
->setType('class')
->setName($workflow_class)
->setLibrary('arcanist')
->selectAndLoadSymbols();
if (!$symbols) {
return null;
}
return newv($workflow_class, array());
return idx($this->buildAllWorkflows(), $command);
}
public function buildAllWorkflows() {
$symbols = id(new PhutilSymbolLoader())
->setType('class')
->setAncestorClass('ArcanistBaseWorkflow')
->setLibrary('arcanist')
->selectAndLoadSymbols();
$workflows = array();
foreach ($symbols as $symbol) {
$class = $symbol['name'];
$name = preg_replace('/^Arcanist(\w+)Workflow$/', '\1', $class);
$name[0] = strtolower($name[0]);
$name = preg_replace_callback(
'/[A-Z]/',
array(
'ArcanistConfiguration',
'replaceClassnameUppers',
),
$name);
$name = strtolower($name);
$workflows[$name] = newv($class, array());
$workflow = newv($class, array());
$name = $workflow->getWorkflowName();
if (isset($workflows[$name])) {
$other = get_class($workflows[$name]);
throw new Exception(
"Workflows {$class} and {$other} both implement workflows named ".
"{$name}.");
}
$workflows[$workflow->getWorkflowName()] = $workflow;
}
return $workflows;
@ -114,12 +90,4 @@ class ArcanistConfiguration {
return array();
}
public static function replaceClassnameHyphens($m) {
return strtoupper($m[1]);
}
public static function replaceClassnameUppers($m) {
return '-'.strtolower($m[0]);
}
}

View file

@ -23,6 +23,10 @@
*/
final class ArcanistAliasWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'alias';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**alias**

View file

@ -23,6 +23,10 @@
*/
final class ArcanistAmendWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'amend';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**amend** [--revision __revision_id__] [--show]

View file

@ -21,6 +21,10 @@
*/
final class ArcanistAnoidWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'anoid';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**anoid**

View file

@ -83,6 +83,14 @@ abstract class ArcanistBaseWorkflow {
abstract public function run();
/**
* Return the command used to invoke this workflow from the command like,
* e.g. "help" for @{class:ArcanistHelpWorkflow}.
*
* @return string The command a user types to invoke this workflow.
*/
abstract public function getWorkflowName();
/* -( Conduit )------------------------------------------------------------ */

View file

@ -25,6 +25,10 @@ final class ArcanistBranchWorkflow extends ArcanistBaseWorkflow {
private $branches;
public function getWorkflowName() {
return 'branch';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**branch** [__options__]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistCallConduitWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'call-conduit';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**call-conduit** __method__

View file

@ -23,6 +23,10 @@
*/
final class ArcanistCloseRevisionWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'close-revision';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**close-revision** [__options__] __revision__

View file

@ -33,6 +33,11 @@ final class ArcanistCloseWorkflow extends ArcanistBaseWorkflow {
"open" => 0
);
public function getWorkflowName() {
return 'close';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**close** __task_id__ [__options__]

View file

@ -25,6 +25,10 @@ final class ArcanistCommitWorkflow extends ArcanistBaseWorkflow {
private $revisionID;
public function getWorkflowName() {
return 'commit';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**commit** [--revision __revision_id__] [--show]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistCoverWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'cover';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**cover** [--rev __revision__] [__path__ ...]

View file

@ -41,6 +41,10 @@ final class ArcanistDiffWorkflow extends ArcanistBaseWorkflow {
private $diffPropertyFutures = array();
private $commitMessageFromRevision;
public function getWorkflowName() {
return 'diff';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**diff** [__paths__] (svn)

View file

@ -27,6 +27,10 @@ final class ArcanistDownloadWorkflow extends ArcanistBaseWorkflow {
private $saveAs;
private $show;
public function getWorkflowName() {
return 'download';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**download** __file__ [--as __name__] [--show]

View file

@ -35,6 +35,10 @@ final class ArcanistExportWorkflow extends ArcanistBaseWorkflow {
private $sourceID;
private $format;
public function getWorkflowName() {
return 'export';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**export** [__paths__] __format__ (svn)

View file

@ -43,6 +43,10 @@ final class ArcanistFlagWorkflow extends ArcanistBaseWorkflow {
'checkered' => 7, 'c' => 7, 7 => 7,
);
public function getWorkflowName() {
return 'flag';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**flag** [__object__ ...]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistGetConfigWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'get-config';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**get-config** -- [__name__ ...]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistGitHookPreReceiveWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'git-hook-pre-receive';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**git-hook-pre-receive**

View file

@ -23,6 +23,10 @@
*/
final class ArcanistHelpWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'help';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**help** [__command__]

View file

@ -21,6 +21,10 @@
*/
final class ArcanistInlinesWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'inlines';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**inlines** [--revision __revision_id__]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistInstallCertificateWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'install-certificate';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**install-certificate** [uri]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'land';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**land** [__options__] [__branch__] [--onto __master__]

View file

@ -29,6 +29,10 @@
*/
final class ArcanistLiberateWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'liberate';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**liberate** [__path__]

View file

@ -36,6 +36,10 @@ class ArcanistLintWorkflow extends ArcanistBaseWorkflow {
private $engine;
private $postponedLinters;
public function getWorkflowName() {
return 'lint';
}
public function setShouldAmendChanges($should_amend) {
$this->shouldAmendChanges = $should_amend;
return $this;

View file

@ -23,6 +23,10 @@
*/
final class ArcanistListWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'list';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**list**

View file

@ -21,6 +21,10 @@
*/
final class ArcanistMarkCommittedWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'mark-committed';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**mark-committed** (DEPRECATED)

View file

@ -28,6 +28,10 @@ final class ArcanistPasteWorkflow extends ArcanistBaseWorkflow {
private $title;
private $json;
public function getWorkflowName() {
return 'paste';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**paste** [--title __title__] [--lang __language__] [--json]

View file

@ -31,6 +31,10 @@ final class ArcanistPatchWorkflow extends ArcanistBaseWorkflow {
private $source;
private $sourceParam;
public function getWorkflowName() {
return 'patch';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**patch** __D12345__

View file

@ -23,6 +23,10 @@
*/
final class ArcanistSetConfigWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'set-config';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**set-config** [__options__] -- __name__ __value__

View file

@ -23,6 +23,10 @@
*/
final class ArcanistShellCompleteWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'shell-complete';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**shell-complete** __--current__ __N__ -- [__argv__]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistSvnHookPreCommitWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'svn-hook-pre-commit';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**svn-hook-pre-commit** __repository__ __transaction__

View file

@ -25,6 +25,10 @@ final class ArcanistTasksWorkflow extends ArcanistBaseWorkflow {
private $tasks;
public function getWorkflowName() {
return 'tasks';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**tasks** [__options__]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistTodoWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'todo';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**todo** __summary__ [__options__]

View file

@ -33,6 +33,10 @@ final class ArcanistUnitWorkflow extends ArcanistBaseWorkflow {
private $testResults;
private $engine;
public function getWorkflowName() {
return 'unit';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**unit** [__options__] [__paths__]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistUpgradeWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'upgrade';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**upgrade**

View file

@ -26,6 +26,10 @@ final class ArcanistUploadWorkflow extends ArcanistBaseWorkflow {
private $paths;
private $json;
public function getWorkflowName() {
return 'upload';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**upload** __file__ [__file__ ...] [--json]

View file

@ -23,6 +23,10 @@
*/
final class ArcanistWhichWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'which';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**which** (svn)