Changeset View
Changeset View
Standalone View
Standalone View
support/ArcanistRuntime.php
| <?php | <?php | ||||
| final class ArcanistRuntime { | final class ArcanistRuntime { | ||||
| private $workflows; | private $workflows; | ||||
| private $logEngine; | |||||
| public function execute(array $argv) { | public function execute(array $argv) { | ||||
| try { | try { | ||||
| $this->checkEnvironment(); | $this->checkEnvironment(); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| echo "CONFIGURATION ERROR\n\n"; | echo "CONFIGURATION ERROR\n\n"; | ||||
| echo $ex->getMessage(); | echo $ex->getMessage(); | ||||
| echo "\n\n"; | echo "\n\n"; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| PhutilTranslator::getInstance() | PhutilTranslator::getInstance() | ||||
| ->setLocale(PhutilLocale::loadLocale('en_US')) | ->setLocale(PhutilLocale::loadLocale('en_US')) | ||||
| ->setTranslations(PhutilTranslation::getTranslationMapForLocale('en_US')); | ->setTranslations(PhutilTranslation::getTranslationMapForLocale('en_US')); | ||||
| $log = new ArcanistLogEngine(); | |||||
| $this->logEngine = $log; | |||||
| try { | try { | ||||
| return $this->executeCore($argv); | return $this->executeCore($argv); | ||||
| } catch (ArcanistConduitException $ex) { | } catch (ArcanistConduitException $ex) { | ||||
| fwrite( | $log->writeError(pht('CONDUIT'), $ex->getMessage()); | ||||
| STDERR, | |||||
| tsprintf( | |||||
| "**%s:** %s\n", | |||||
| pht('Conduit Exception'), | |||||
| $ex->getMessage())); | |||||
| } catch (PhutilArgumentUsageException $ex) { | } catch (PhutilArgumentUsageException $ex) { | ||||
| fwrite( | $log->writeError(pht('USAGE EXCEPTION'), $ex->getMessage()); | ||||
| STDERR, | |||||
| tsprintf( | |||||
| "**%s:** %s\n", | |||||
| pht('Usage Exception'), | |||||
| $ex->getMessage())); | |||||
| return 77; | |||||
amckinley: lolwut | |||||
| } | } | ||||
| return 1; | |||||
Not Done Inline ActionsAssuming this is the saner version of return 77;. amckinley: Assuming this is the saner version of `return 77;`. | |||||
Done Inline ActionsYeah. I noted that we no longer have random crazy behavior in T13203 OwO *drops spork* epriestley: Yeah. I noted that we no longer have random crazy behavior in T13203 OwO *drops spork* | |||||
| } | } | ||||
| private function executeCore(array $argv) { | private function executeCore(array $argv) { | ||||
| $log = $this->getLogEngine(); | |||||
| $config_args = array( | $config_args = array( | ||||
| array( | array( | ||||
| 'name' => 'library', | 'name' => 'library', | ||||
| 'param' => 'path', | 'param' => 'path', | ||||
| 'help' => pht('Load a library.'), | 'help' => pht('Load a library.'), | ||||
| 'repeat' => true, | 'repeat' => true, | ||||
| ), | ), | ||||
| array( | array( | ||||
| Show All 11 Lines | $config_args = array( | ||||
| 'the system and user configuration files are ignored.'), | 'the system and user configuration files are ignored.'), | ||||
| ), | ), | ||||
| ); | ); | ||||
| $args = id(new PhutilArgumentParser($argv)) | $args = id(new PhutilArgumentParser($argv)) | ||||
| ->parseStandardArguments(); | ->parseStandardArguments(); | ||||
| $is_trace = $args->getArg('trace'); | $is_trace = $args->getArg('trace'); | ||||
| if ($is_trace) { | $log->setShowTraceMessages($is_trace); | ||||
| $this->logTrace(pht('ARGV'), csprintf('%Ls', $argv)); | |||||
| } | $log->writeTrace(pht('ARGV'), csprintf('%Ls', $argv)); | ||||
| $args->parsePartial($config_args, true); | $args->parsePartial($config_args, true); | ||||
| $config_engine = $this->loadConfiguration($args); | $config_engine = $this->loadConfiguration($args); | ||||
| $config = $config_engine->newConfigurationSourceList(); | $config = $config_engine->newConfigurationSourceList(); | ||||
| $this->loadLibraries($args, $config); | $this->loadLibraries($args, $config); | ||||
| // Now that we've loaded libraries, we can validate configuration. | // Now that we've loaded libraries, we can validate configuration. | ||||
| // Do this before continuing since configuration can impact other | // Do this before continuing since configuration can impact other | ||||
| // behaviors immediately and we want to catch any issues right away. | // behaviors immediately and we want to catch any issues right away. | ||||
| $config->setConfigOptions($config_engine->newConfigOptionsMap()); | $config->setConfigOptions($config_engine->newConfigOptionsMap()); | ||||
| $config->validateConfiguration(); | $config->validateConfiguration($this); | ||||
| $toolset = $this->newToolset($argv); | $toolset = $this->newToolset($argv); | ||||
| $args->parsePartial($toolset->getToolsetArguments()); | $args->parsePartial($toolset->getToolsetArguments()); | ||||
| $workflows = $this->newWorkflows($toolset); | $workflows = $this->newWorkflows($toolset); | ||||
| $this->workflows = $workflows; | $this->workflows = $workflows; | ||||
| ▲ Show 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | foreach ($workflows as $workflow) { | ||||
| } | } | ||||
| $map[$key] = id(clone $workflow) | $map[$key] = id(clone $workflow) | ||||
| ->setToolset($toolset); | ->setToolset($toolset); | ||||
| } | } | ||||
| return $map; | return $map; | ||||
| } | } | ||||
| private function logTrace($label, $message) { | |||||
| echo tsprintf( | |||||
| "**<bg:magenta> %s </bg>** %s\n", | |||||
| $label, | |||||
| $message); | |||||
| } | |||||
| public function getWorkflows() { | public function getWorkflows() { | ||||
| return $this->workflows; | return $this->workflows; | ||||
| } | } | ||||
| public function getLogEngine() { | |||||
| return $this->logEngine; | |||||
| } | |||||
| private function applyAliasEffects(array $effects, array $argv) { | private function applyAliasEffects(array $effects, array $argv) { | ||||
| assert_instances_of($effects, 'ArcanistAliasEffect'); | assert_instances_of($effects, 'ArcanistAliasEffect'); | ||||
| $log = $this->getLogEngine(); | |||||
| $command = null; | $command = null; | ||||
| $arguments = null; | $arguments = null; | ||||
| foreach ($effects as $effect) { | foreach ($effects as $effect) { | ||||
| $message = $effect->getMessage(); | $message = $effect->getMessage(); | ||||
| if ($message !== null) { | if ($message !== null) { | ||||
| fprintf( | $log->writeInfo(pht('ALIAS'), $message); | ||||
| STDERR, | |||||
| tsprintf( | |||||
| "**<bg:yellow> %s </bg>** %s\n", | |||||
| pht('ALIAS'), | |||||
| $message)); | |||||
| } | } | ||||
| if ($effect->getCommand()) { | if ($effect->getCommand()) { | ||||
| $command = $effect->getCommand(); | $command = $effect->getCommand(); | ||||
| $arguments = $effect->getArguments(); | $arguments = $effect->getArguments(); | ||||
| } | } | ||||
| } | } | ||||
| if ($command !== null) { | if ($command !== null) { | ||||
| $argv = array_merge(array($command), $arguments); | $argv = array_merge(array($command), $arguments); | ||||
| } | } | ||||
| return $argv; | return $argv; | ||||
| } | } | ||||
| } | } | ||||
lolwut