diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 15bb86ce..12416504 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -325,6 +325,7 @@ phutil_register_library_map(array( 'ArcanistLogMessage' => 'log/ArcanistLogMessage.php', 'ArcanistLogicalOperatorsXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistLogicalOperatorsXHPASTLinterRule.php', 'ArcanistLogicalOperatorsXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistLogicalOperatorsXHPASTLinterRuleTestCase.php', + 'ArcanistLookWorkflow' => 'workflow/ArcanistLookWorkflow.php', 'ArcanistLowercaseFunctionsXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistLowercaseFunctionsXHPASTLinterRule.php', 'ArcanistLowercaseFunctionsXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistLowercaseFunctionsXHPASTLinterRuleTestCase.php', 'ArcanistMarkerRef' => 'repository/marker/ArcanistMarkerRef.php', @@ -1354,6 +1355,7 @@ phutil_register_library_map(array( 'ArcanistLogMessage' => 'Phobject', 'ArcanistLogicalOperatorsXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistLogicalOperatorsXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase', + 'ArcanistLookWorkflow' => 'ArcanistArcWorkflow', 'ArcanistLowercaseFunctionsXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistLowercaseFunctionsXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase', 'ArcanistMarkerRef' => 'ArcanistRef', diff --git a/src/repository/remote/ArcanistRemoteRef.php b/src/repository/remote/ArcanistRemoteRef.php index c901baec..40092798 100644 --- a/src/repository/remote/ArcanistRemoteRef.php +++ b/src/repository/remote/ArcanistRemoteRef.php @@ -38,4 +38,8 @@ final class ArcanistRemoteRef return $this->pushURI; } + protected function buildRefView(ArcanistRefView $view) { + $view->setObjectName($this->getRemoteName()); + } + } diff --git a/src/workflow/ArcanistLookWorkflow.php b/src/workflow/ArcanistLookWorkflow.php new file mode 100644 index 00000000..58e23e35 --- /dev/null +++ b/src/workflow/ArcanistLookWorkflow.php @@ -0,0 +1,171 @@ +newWorkflowInformation() + ->setSynopsis( + pht('You stand in the middle of a small clearing.')) + ->addExample('**look**') + ->addExample('**look** [options] -- __thing__') + ->setHelp($help); + } + + public function getWorkflowArguments() { + return array( + $this->newWorkflowArgument('argv') + ->setWildcard(true), + ); + } + + public function runWorkflow() { + echo tsprintf( + "%!\n\n", + pht( + 'Arcventure')); + + $argv = $this->getArgument('argv'); + + if ($argv) { + if ($argv === array('remotes')) { + return $this->lookRemotes(); + } + + echo tsprintf( + "%s\n", + pht( + 'You do not see "%s" anywhere.', + implode(' ', $argv))); + + return 1; + } + + echo tsprintf( + "%W\n\n", + pht( + 'You stand in the middle of a small clearing in the woods.')); + + $now = time(); + $hour = (int)date('h', $now); + + if ($hour >= 5 && $hour <= 7) { + $time = pht( + 'It is early morning. Glimses of sunlight peek through the trees '. + 'and you hear the faint sound of birds overhead.'); + } else if ($hour >= 8 && $hour <= 10) { + $time = pht( + 'It is morning. The sun is high in the sky to the east and you hear '. + 'birds all around you. A gentle breeze rustles the leaves overhead.'); + } else if ($hour >= 11 && $hour <= 13) { + $time = pht( + 'It is midday. The sun is high overhead and the air is still. It is '. + 'very warm. You hear the cry of a hawk high overhead and far in the '. + 'distance.'); + } else if ($hour >= 14 && $hour <= 16) { + $time = pht( + 'It is afternoon. The air has changed and it feels as though it '. + 'may rain. You hear a squirrel chittering high overhead.'); + } else if ($hour >= 17 && $hour <= 19) { + $time = pht( + 'It is nearly dusk. The wind has picked up and the trees around you '. + 'sway and rustle.'); + } else if ($hour >= 21 && $hour <= 23) { + $time = pht( + 'It is late in the evening. The air is cool and still, and filled '. + 'with the sound of crickets.'); + } else { + $phase = new PhutilLunarPhase($now); + if ($phase->isNew()) { + $time = pht( + 'Night has fallen, and the thin sliver of moon overhead offers '. + 'no comfort. It is almost pitch black. The night is bitter '. + 'cold. It will be difficult to look around in these conditions.'); + } else if ($phase->isFull()) { + $time = pht( + 'Night has fallen, but your surroundings are illuminated by the '. + 'silvery glow of a full moon overhead. The night is cool and '. + 'the air is crisp. The trees are calm.'); + } else if ($phase->isWaxing()) { + $time = pht( + 'Night has fallen. The moon overhead is waxing, and provides '. + 'just enough light that you can make out your surroundings. It '. + 'is quite cold.'); + } else if ($phase->isWaning()) { + $time = pht( + 'Night has fallen. The moon overhead is waning. You can barely '. + 'make out your surroundings. It is very cold.'); + } + } + + echo tsprintf( + "%W\n\n", + $time); + + echo tsprintf( + "%W\n\n", + pht( + 'Several small trails and footpaths cross here, twisting away from '. + 'you among the trees.')); + + echo tsprintf( + pht("Just ahead to the north, you can see **remotes**.\n")); + + return 0; + } + + private function lookRemotes() { + echo tsprintf( + "%W\n\n", + pht( + 'You follow a wide, straight path to the north and arrive in a '. + 'grove of fruit trees after a few minutes of walking. The grass '. + 'underfoot is thick and small insects flit through the air.')); + + echo tsprintf( + "%W\n\n", + pht( + 'At the far edge of the grove, you see remotes:')); + + $api = $this->getRepositoryAPI(); + + $remotes = $api->newRemoteRefQuery() + ->execute(); + foreach ($remotes as $remote) { + + $view = $remote->newRefView(); + + $push_uri = $remote->getPushURI(); + if ($push_uri === null) { + $push_uri = '-'; + } + + $view->appendLine( + pht( + 'Push URI: %s', + $push_uri)); + + $fetch_uri = $remote->getFetchURI(); + if ($fetch_uri === null) { + $fetch_uri = '-'; + } + + $view->appendLine( + pht( + 'Fetch URI: %s', + $fetch_uri)); + + echo tsprintf('%s', $view); + } + } + +}