forked from phacility/arcanist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
epriestley
committed
Apr 11, 2020
1 parent
387027e
commit ccd1ebb
Showing
5 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
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. | ||
if [ ! -f "${SCRIPTDIR}/bash-rules.sh" ]; then | ||
if [ ! -f "${GENERATED_RULES_FILE}" ]; then | ||
arc shell-complete --generate >/dev/null 2>/dev/null | ||
fi; | ||
|
||
# Source the shell completion rules. | ||
source "${SCRIPTDIR}/../rules/bash-rules.sh" | ||
source "${GENERATED_RULES_FILE}" |