1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Update "arc call-conduit" for Toolsets

Summary: Ref T13490. Fairly straightforward update.

Test Plan: Made various Conduit calls.

Maniphest Tasks: T13490

Differential Revision: https://secure.phabricator.com/D21096
This commit is contained in:
epriestley 2020-04-12 14:11:30 -07:00
parent 0f2e277cd9
commit 076f7be484
3 changed files with 52 additions and 56 deletions

View file

@ -924,6 +924,7 @@ phutil_register_library_map(array(
'phutil_http_parameter_pair' => 'utils/utils.php',
'phutil_ini_decode' => 'utils/utils.php',
'phutil_is_hiphop_runtime' => 'utils/utils.php',
'phutil_is_interactive' => 'utils/utils.php',
'phutil_is_natural_list' => 'utils/utils.php',
'phutil_is_noninteractive' => 'utils/utils.php',
'phutil_is_system_locale_available' => 'utils/utf8.php',
@ -1052,7 +1053,7 @@ phutil_register_library_map(array(
'ArcanistCSSLintLinter' => 'ArcanistExternalLinter',
'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCSharpLinter' => 'ArcanistLinter',
'ArcanistCallConduitWorkflow' => 'ArcanistWorkflow',
'ArcanistCallConduitWorkflow' => 'ArcanistArcWorkflow',
'ArcanistCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistCallParenthesesXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',

View file

@ -1927,6 +1927,14 @@ function phutil_is_noninteractive() {
return false;
}
function phutil_is_interactive() {
if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
return true;
}
return false;
}
function phutil_encode_log($message) {
return addcslashes($message, "\0..\37\\\177..\377");
}

View file

@ -1,71 +1,55 @@
<?php
/**
* Provides command-line access to the Conduit API.
*/
final class ArcanistCallConduitWorkflow extends ArcanistWorkflow {
final class ArcanistCallConduitWorkflow
extends ArcanistArcWorkflow {
public function getWorkflowName() {
return 'call-conduit';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**call-conduit** __method__
public function getWorkflowInformation() {
$help = pht(<<<EOTEXT
Allows you to make a raw Conduit method call:
- Run this command from a working directory.
- Call parameters are required, and read as a JSON blob from stdin.
- Results are written to stdout as a JSON blob.
This workflow is primarily useful for writing scripts which integrate
with Phabricator. Examples:
$ echo '{}' | arc call-conduit -- conduit.ping
$ echo '{"phid":"PHID-FILE-xxxx"}' | arc call-conduit -- file.download
EOTEXT
);
return $this->newWorkflowInformation()
->setSynopsis(pht('Call Conduit API methods.'))
->addExample('**call-conduit** -- __method__')
->setHelp($help);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: http, https
Allows you to make a raw Conduit method call:
- Run this command from a working directory.
- Call parameters are REQUIRED and read as a JSON blob from stdin.
- Results are written to stdout as a JSON blob.
This workflow is primarily useful for writing scripts which integrate
with Phabricator. Examples:
$ echo '{}' | arc call-conduit conduit.ping
$ echo '{"phid":"PHID-FILE-xxxx"}' | arc call-conduit file.download
EOTEXT
);
}
public function getArguments() {
public function getWorkflowArguments() {
return array(
'*' => 'method',
$this->newWorkflowArgument('method')
->setWildcard(true),
);
}
protected function shouldShellComplete() {
return false;
}
public function requiresConduit() {
return true;
}
public function requiresAuthentication() {
return true;
}
public function run() {
$method = $this->getArgument('method', array());
public function runWorkflow() {
$method = $this->getArgument('method');
if (count($method) !== 1) {
throw new ArcanistUsageException(
pht('Provide exactly one Conduit method name.'));
throw new PhutilArgumentUsageException(
pht('Provide exactly one Conduit method name to call.'));
}
$method = reset($method);
$method = head($method);
$console = PhutilConsole::getConsole();
if (!function_exists('posix_isatty') || posix_isatty(STDIN)) {
$console->writeErr(
if (phutil_is_interactive()) {
echo tsprintf(
"%s\n",
pht('Waiting for JSON parameters on stdin...'));
}
$params = @file_get_contents('php://stdin');
try {
$params = phutil_json_decode($params);
@ -74,23 +58,26 @@ EOTEXT
pht('Provide method parameters on stdin as a JSON blob.'));
}
$engine = $this->getConduitEngine();
$conduit_call = $engine->newCall($method, $params);
$conduit_future = $engine->newFuture($conduit_call);
$error = null;
$error_message = null;
try {
$result = $this->getConduit()->callMethodSynchronous(
$method,
$params);
$result = $conduit_future->resolve();
} catch (ConduitClientException $ex) {
$error = $ex->getErrorCode();
$error_message = $ex->getMessage();
$result = null;
}
echo json_encode(array(
'error' => $error,
'errorMessage' => $error_message,
'response' => $result,
))."\n";
echo id(new PhutilJSON())->encodeFormatted(
array(
'error' => $error,
'errorMessage' => $error_message,
'response' => $result,
));
return 0;
}