From: epriestley Date: Wed, 17 Oct 2012 15:35:03 +0000 (-0700) Subject: Make Arcanist workflow names explicit X-Git-Tag: conduit-6~81 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4c476c0201d3e9d9fbb4254028cb06c817ca3c22;p=arcanist.git 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 --- diff --git a/src/configuration/ArcanistConfiguration.php b/src/configuration/ArcanistConfiguration.php index 02f39566..be5c8921 100644 --- a/src/configuration/ArcanistConfiguration.php +++ b/src/configuration/ArcanistConfiguration.php @@ -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]); - } - } diff --git a/src/workflow/ArcanistAliasWorkflow.php b/src/workflow/ArcanistAliasWorkflow.php index 8c2c5726..a91428f9 100644 --- a/src/workflow/ArcanistAliasWorkflow.php +++ b/src/workflow/ArcanistAliasWorkflow.php @@ -23,6 +23,10 @@ */ final class ArcanistAliasWorkflow extends ArcanistBaseWorkflow { + public function getWorkflowName() { + return 'alias'; + } + public function getCommandSynopses() { return phutil_console_format(<< 0 ); + + public function getWorkflowName() { + return 'close'; + } + public function getCommandSynopses() { return phutil_console_format(<< 7, 'c' => 7, 7 => 7, ); + public function getWorkflowName() { + return 'flag'; + } + public function getCommandSynopses() { return phutil_console_format(<<shouldAmendChanges = $should_amend; return $this; diff --git a/src/workflow/ArcanistListWorkflow.php b/src/workflow/ArcanistListWorkflow.php index 5c5d8bff..c3486edc 100644 --- a/src/workflow/ArcanistListWorkflow.php +++ b/src/workflow/ArcanistListWorkflow.php @@ -23,6 +23,10 @@ */ final class ArcanistListWorkflow extends ArcanistBaseWorkflow { + public function getWorkflowName() { + return 'list'; + } + public function getCommandSynopses() { return phutil_console_format(<<