Changeset View
Changeset View
Standalone View
Standalone View
src/toolset/workflow/ArcanistPromptsWorkflow.php
<?php | <?php | ||||
final class ArcanistPromptsWorkflow extends ArcanistWorkflow { | final class ArcanistPromptsWorkflow | ||||
extends ArcanistWorkflow { | |||||
public function supportsToolset(ArcanistToolset $toolset) { | public function supportsToolset(ArcanistToolset $toolset) { | ||||
return true; | return true; | ||||
} | } | ||||
public function getWorkflowName() { | public function getWorkflowName() { | ||||
return 'prompts'; | return 'prompts'; | ||||
} | } | ||||
public function getWorkflowInformation() { | public function getWorkflowInformation() { | ||||
$help = pht(<<<EOTEXT | $help = pht(<<<EOTEXT | ||||
Show information about prompts a workflow may execute and configure default | Show information about prompts a workflow may execute, and review saved | ||||
responses. | responses. | ||||
**Show Prompts** | **Show Prompts** | ||||
To show possible prompts a workflow may execute, run: | To show possible prompts a workflow may execute, run: | ||||
$ arc prompts <workflow> | $ arc prompts __workflow__ | ||||
**Saving Responses** | |||||
If you always want to answer a particular prompt in a certain way, you can | |||||
save your response to the prompt. When you encounter the prompt again, your | |||||
saved response will be used automatically. | |||||
To save a response, add "*" or "!" to the end of the response you want to save | |||||
when you answer the prompt: | |||||
- Using "*" will save the response in user configuration. In the future, | |||||
the saved answer will be used any time you encounter the prompt (in any | |||||
project). | |||||
- Using "!" will save the response in working copy configuration. In the | |||||
future, the saved answer will be used when you encounter the prompt in | |||||
the current working copy. | |||||
For example, if you would like to always answer "y" to a particular prompt, | |||||
respond with "y*" or "y!" to save your response. | |||||
EOTEXT | EOTEXT | ||||
); | ); | ||||
return $this->newWorkflowInformation() | return $this->newWorkflowInformation() | ||||
->addExample(pht('**prompts** __workflow__')) | ->addExample(pht('**prompts** __workflow__')) | ||||
->setHelp($help); | ->setHelp($help); | ||||
} | } | ||||
Show All 29 Lines | public function runWorkflow() { | ||||
$prompts = $workflow->getPromptMap(); | $prompts = $workflow->getPromptMap(); | ||||
if (!$prompts) { | if (!$prompts) { | ||||
echo tsprintf( | echo tsprintf( | ||||
"%s\n", | "%s\n", | ||||
pht('This workflow does not have any prompts.')); | pht('This workflow does not have any prompts.')); | ||||
return 0; | return 0; | ||||
} | } | ||||
$prompts = msort($prompts, 'getKey'); | |||||
$blocks = array(); | |||||
foreach ($prompts as $prompt) { | foreach ($prompts as $prompt) { | ||||
echo tsprintf( | $block = array(); | ||||
"**%s**\n", | $block[] = tsprintf( | ||||
"<bg:green>** %s **</bg> **%s**\n\n", | |||||
pht('PROMPT'), | |||||
$prompt->getKey()); | $prompt->getKey()); | ||||
echo tsprintf( | $block[] = tsprintf( | ||||
"%s\n", | "%W\n", | ||||
$prompt->getDescription()); | $prompt->getDescription()); | ||||
$responses = $this->getSavedResponses($prompt->getKey()); | |||||
if ($responses) { | |||||
$block[] = tsprintf("\n"); | |||||
foreach ($responses as $response) { | |||||
$block[] = tsprintf( | |||||
" <bg:cyan>** > **</bg> %s\n", | |||||
pht( | |||||
'You have saved the response "%s" to this prompt.', | |||||
$response->getResponse())); | |||||
} | |||||
} | |||||
$blocks[] = $block; | |||||
} | } | ||||
echo tsprintf('%B', phutil_glue($blocks, tsprintf("\n"))); | |||||
return 0; | return 0; | ||||
} | } | ||||
private function getSavedResponses($prompt_key) { | |||||
$config_key = ArcanistArcConfigurationEngineExtension::KEY_PROMPTS; | |||||
$config = $this->getConfig($config_key); | |||||
$responses = array(); | |||||
foreach ($config as $response) { | |||||
if ($response->getPrompt() === $prompt_key) { | |||||
$responses[] = $response; | |||||
} | |||||
} | |||||
return $responses; | |||||
} | |||||
} | } |