diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f0e69db7..e9e19fdf 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/utils/utils.php b/src/utils/utils.php index 2e1d2b09..9f454017 100644 --- a/src/utils/utils.php +++ b/src/utils/utils.php @@ -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"); } diff --git a/src/workflow/ArcanistCallConduitWorkflow.php b/src/workflow/ArcanistCallConduitWorkflow.php index c6d3a464..324b5fe9 100644 --- a/src/workflow/ArcanistCallConduitWorkflow.php +++ b/src/workflow/ArcanistCallConduitWorkflow.php @@ -1,71 +1,55 @@ newWorkflowInformation() + ->setSynopsis(pht('Call Conduit API methods.')) + ->addExample('**call-conduit** -- __method__') + ->setHelp($help); } - public function getCommandHelp() { - return phutil_console_format(<< '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; }