1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +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_http_parameter_pair' => 'utils/utils.php',
'phutil_ini_decode' => 'utils/utils.php', 'phutil_ini_decode' => 'utils/utils.php',
'phutil_is_hiphop_runtime' => '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_natural_list' => 'utils/utils.php',
'phutil_is_noninteractive' => 'utils/utils.php', 'phutil_is_noninteractive' => 'utils/utils.php',
'phutil_is_system_locale_available' => 'utils/utf8.php', 'phutil_is_system_locale_available' => 'utils/utf8.php',
@ -1052,7 +1053,7 @@ phutil_register_library_map(array(
'ArcanistCSSLintLinter' => 'ArcanistExternalLinter', 'ArcanistCSSLintLinter' => 'ArcanistExternalLinter',
'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase', 'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCSharpLinter' => 'ArcanistLinter', 'ArcanistCSharpLinter' => 'ArcanistLinter',
'ArcanistCallConduitWorkflow' => 'ArcanistWorkflow', 'ArcanistCallConduitWorkflow' => 'ArcanistArcWorkflow',
'ArcanistCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistCallParenthesesXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase', 'ArcanistCallParenthesesXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',

View file

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

View file

@ -1,71 +1,55 @@
<?php <?php
/** final class ArcanistCallConduitWorkflow
* Provides command-line access to the Conduit API. extends ArcanistArcWorkflow {
*/
final class ArcanistCallConduitWorkflow extends ArcanistWorkflow {
public function getWorkflowName() { public function getWorkflowName() {
return 'call-conduit'; return 'call-conduit';
} }
public function getCommandSynopses() { public function getWorkflowInformation() {
return phutil_console_format(<<<EOTEXT $help = pht(<<<EOTEXT
**call-conduit** __method__ 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 EOTEXT
); );
return $this->newWorkflowInformation()
->setSynopsis(pht('Call Conduit API methods.'))
->addExample('**call-conduit** -- __method__')
->setHelp($help);
} }
public function getCommandHelp() { public function getWorkflowArguments() {
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() {
return array( return array(
'*' => 'method', $this->newWorkflowArgument('method')
->setWildcard(true),
); );
} }
protected function shouldShellComplete() { public function runWorkflow() {
return false; $method = $this->getArgument('method');
}
public function requiresConduit() {
return true;
}
public function requiresAuthentication() {
return true;
}
public function run() {
$method = $this->getArgument('method', array());
if (count($method) !== 1) { if (count($method) !== 1) {
throw new ArcanistUsageException( throw new PhutilArgumentUsageException(
pht('Provide exactly one Conduit method name.')); pht('Provide exactly one Conduit method name to call.'));
} }
$method = reset($method); $method = head($method);
$console = PhutilConsole::getConsole(); if (phutil_is_interactive()) {
if (!function_exists('posix_isatty') || posix_isatty(STDIN)) { echo tsprintf(
$console->writeErr(
"%s\n", "%s\n",
pht('Waiting for JSON parameters on stdin...')); pht('Waiting for JSON parameters on stdin...'));
} }
$params = @file_get_contents('php://stdin'); $params = @file_get_contents('php://stdin');
try { try {
$params = phutil_json_decode($params); $params = phutil_json_decode($params);
@ -74,23 +58,26 @@ EOTEXT
pht('Provide method parameters on stdin as a JSON blob.')); 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 = null;
$error_message = null; $error_message = null;
try { try {
$result = $this->getConduit()->callMethodSynchronous( $result = $conduit_future->resolve();
$method,
$params);
} catch (ConduitClientException $ex) { } catch (ConduitClientException $ex) {
$error = $ex->getErrorCode(); $error = $ex->getErrorCode();
$error_message = $ex->getMessage(); $error_message = $ex->getMessage();
$result = null; $result = null;
} }
echo json_encode(array( echo id(new PhutilJSON())->encodeFormatted(
'error' => $error, array(
'errorMessage' => $error_message, 'error' => $error,
'response' => $result, 'errorMessage' => $error_message,
))."\n"; 'response' => $result,
));
return 0; return 0;
} }