mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Port "arc prompts" from wilds and fix a path issue in shell completion
Summary: Ref T13490. Bring "arc prompts" from "wilds" and hook it into the prompt in "arc shell-complete". See D21069. Fix an issue where the shell hook tested for a path other than the path it writes to. Test Plan: Ran "arc shell-complete" with no hook and got a prompt. Shell completed things. Ran "arc prompts shell-complete". Maniphest Tasks: T13490 Differential Revision: https://secure.phabricator.com/D21085
This commit is contained in:
parent
387027eb3a
commit
ccd1ebb256
5 changed files with 149 additions and 3 deletions
|
@ -370,6 +370,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase.php',
|
'ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase.php',
|
||||||
'ArcanistProjectConfigurationSource' => 'config/source/ArcanistProjectConfigurationSource.php',
|
'ArcanistProjectConfigurationSource' => 'config/source/ArcanistProjectConfigurationSource.php',
|
||||||
'ArcanistPrompt' => 'toolset/ArcanistPrompt.php',
|
'ArcanistPrompt' => 'toolset/ArcanistPrompt.php',
|
||||||
|
'ArcanistPromptsWorkflow' => 'toolset/workflow/ArcanistPromptsWorkflow.php',
|
||||||
'ArcanistPublicPropertyXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPublicPropertyXHPASTLinterRule.php',
|
'ArcanistPublicPropertyXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistPublicPropertyXHPASTLinterRule.php',
|
||||||
'ArcanistPublicPropertyXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistPublicPropertyXHPASTLinterRuleTestCase.php',
|
'ArcanistPublicPropertyXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistPublicPropertyXHPASTLinterRuleTestCase.php',
|
||||||
'ArcanistPuppetLintLinter' => 'lint/linter/ArcanistPuppetLintLinter.php',
|
'ArcanistPuppetLintLinter' => 'lint/linter/ArcanistPuppetLintLinter.php',
|
||||||
|
@ -1330,6 +1331,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
|
'ArcanistPlusOperatorOnStringsXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
|
||||||
'ArcanistProjectConfigurationSource' => 'ArcanistWorkingCopyConfigurationSource',
|
'ArcanistProjectConfigurationSource' => 'ArcanistWorkingCopyConfigurationSource',
|
||||||
'ArcanistPrompt' => 'Phobject',
|
'ArcanistPrompt' => 'Phobject',
|
||||||
|
'ArcanistPromptsWorkflow' => 'ArcanistWorkflow',
|
||||||
'ArcanistPublicPropertyXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistPublicPropertyXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
'ArcanistPublicPropertyXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
|
'ArcanistPublicPropertyXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
|
||||||
'ArcanistPuppetLintLinter' => 'ArcanistExternalLinter',
|
'ArcanistPuppetLintLinter' => 'ArcanistExternalLinter',
|
||||||
|
|
80
src/toolset/workflow/ArcanistPromptsWorkflow.php
Normal file
80
src/toolset/workflow/ArcanistPromptsWorkflow.php
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistPromptsWorkflow extends ArcanistWorkflow {
|
||||||
|
|
||||||
|
public function supportsToolset(ArcanistToolset $toolset) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWorkflowName() {
|
||||||
|
return 'prompts';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWorkflowInformation() {
|
||||||
|
$help = pht(<<<EOTEXT
|
||||||
|
Show information about prompts a workflow may execute and configure default
|
||||||
|
responses.
|
||||||
|
|
||||||
|
**Show Prompts**
|
||||||
|
|
||||||
|
To show possible prompts a workflow may execute, run:
|
||||||
|
|
||||||
|
$ arc prompts <workflow>
|
||||||
|
EOTEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->newWorkflowInformation()
|
||||||
|
->addExample(pht('**prompts** __workflow__'))
|
||||||
|
->setHelp($help);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWorkflowArguments() {
|
||||||
|
return array(
|
||||||
|
$this->newWorkflowArgument('argv')
|
||||||
|
->setWildcard(true),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function runWorkflow() {
|
||||||
|
$argv = $this->getArgument('argv');
|
||||||
|
|
||||||
|
if (!$argv) {
|
||||||
|
throw new PhutilArgumentUsageException(
|
||||||
|
pht('Provide a workflow to list prompts for.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$runtime = $this->getRuntime();
|
||||||
|
$workflows = $runtime->getWorkflows();
|
||||||
|
|
||||||
|
$workflow_key = array_shift($argv);
|
||||||
|
$workflow = idx($workflows, $workflow_key);
|
||||||
|
|
||||||
|
if (!$workflow) {
|
||||||
|
throw new PhutilArgumentUsageException(
|
||||||
|
pht(
|
||||||
|
'Workflow "%s" is unknown. Supported workflows are: %s.',
|
||||||
|
$workflow_key,
|
||||||
|
implode(', ', array_keys($workflows))));
|
||||||
|
}
|
||||||
|
|
||||||
|
$prompts = $workflow->getPromptMap();
|
||||||
|
if (!$prompts) {
|
||||||
|
echo tsprintf(
|
||||||
|
"%s\n",
|
||||||
|
pht('This workflow does not have any prompts.'));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($prompts as $prompt) {
|
||||||
|
echo tsprintf(
|
||||||
|
"**%s**\n",
|
||||||
|
$prompt->getKey());
|
||||||
|
echo tsprintf(
|
||||||
|
"%s\n",
|
||||||
|
$prompt->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -226,7 +226,10 @@ EOTEXT
|
||||||
|
|
||||||
$log->writeSuccess(
|
$log->writeSuccess(
|
||||||
pht('INSTALL'),
|
pht('INSTALL'),
|
||||||
pht('Installing shell completion support for "%s".', $shell));
|
pht(
|
||||||
|
'Installing shell completion support for "%s" into "%s".',
|
||||||
|
$shell,
|
||||||
|
$file_display));
|
||||||
|
|
||||||
if ($replace) {
|
if ($replace) {
|
||||||
$replace_pos = $matches[0][1];
|
$replace_pos = $matches[0][1];
|
||||||
|
|
|
@ -77,6 +77,7 @@ abstract class ArcanistWorkflow extends Phobject {
|
||||||
private $configurationSourceList;
|
private $configurationSourceList;
|
||||||
|
|
||||||
private $hardpointEngine;
|
private $hardpointEngine;
|
||||||
|
private $promptMap;
|
||||||
|
|
||||||
final public function setToolset(ArcanistToolset $toolset) {
|
final public function setToolset(ArcanistToolset $toolset) {
|
||||||
$this->toolset = $toolset;
|
$this->toolset = $toolset;
|
||||||
|
@ -2333,4 +2334,63 @@ abstract class ArcanistWorkflow extends Phobject {
|
||||||
return $engine;
|
return $engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function newPrompts() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newPrompt($key) {
|
||||||
|
return id(new ArcanistPrompt())
|
||||||
|
->setWorkflow($this)
|
||||||
|
->setKey($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasPrompt($key) {
|
||||||
|
$map = $this->getPromptMap();
|
||||||
|
return isset($map[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPromptMap() {
|
||||||
|
if ($this->promptMap === null) {
|
||||||
|
$prompts = $this->newPrompts();
|
||||||
|
assert_instances_of($prompts, 'ArcanistPrompt');
|
||||||
|
|
||||||
|
$map = array();
|
||||||
|
foreach ($prompts as $prompt) {
|
||||||
|
$key = $prompt->getKey();
|
||||||
|
|
||||||
|
if (isset($map[$key])) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Workflow ("%s") generates two prompts with the same '.
|
||||||
|
'key ("%s"). Each prompt a workflow generates must have a '.
|
||||||
|
'unique key.',
|
||||||
|
get_class($this),
|
||||||
|
$key));
|
||||||
|
}
|
||||||
|
|
||||||
|
$map[$key] = $prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->promptMap = $map;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->promptMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getPrompt($key) {
|
||||||
|
$map = $this->getPromptMap();
|
||||||
|
|
||||||
|
$prompt = idx($map, $key);
|
||||||
|
if (!$prompt) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Workflow ("%s") is requesting a prompt ("%s") but it did not '.
|
||||||
|
'generate any prompt with that name in "newPrompts()".',
|
||||||
|
get_class($this),
|
||||||
|
$key));
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone $prompt;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
|
||||||
|
GENERATED_RULES_FILE="${SCRIPTDIR}/../rules/bash-rules.sh"
|
||||||
|
|
||||||
# Try to generate the shell completion rules if they do not yet exist.
|
# Try to generate the shell completion rules if they do not yet exist.
|
||||||
if [ ! -f "${SCRIPTDIR}/bash-rules.sh" ]; then
|
if [ ! -f "${GENERATED_RULES_FILE}" ]; then
|
||||||
arc shell-complete --generate >/dev/null 2>/dev/null
|
arc shell-complete --generate >/dev/null 2>/dev/null
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
# Source the shell completion rules.
|
# Source the shell completion rules.
|
||||||
source "${SCRIPTDIR}/../rules/bash-rules.sh"
|
source "${GENERATED_RULES_FILE}"
|
||||||
|
|
Loading…
Reference in a new issue