2011-05-06 17:43:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides command-line access to the Conduit API.
|
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
final class ArcanistCallConduitWorkflow extends ArcanistWorkflow {
|
2011-05-06 17:43:38 +02:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'call-conduit';
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-05-06 17:43:38 +02:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**call-conduit** __method__
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2011-05-06 17:43:38 +02:00
|
|
|
Supports: http, https
|
2011-06-23 02:52:37 +02:00
|
|
|
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
|
2011-05-06 17:43:38 +02:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'*' => 'method',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:36:00 +01:00
|
|
|
protected function shouldShellComplete() {
|
2011-05-06 17:43:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:03:40 +02:00
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-05-06 17:43:38 +02:00
|
|
|
public function run() {
|
|
|
|
$method = $this->getArgument('method', array());
|
|
|
|
if (count($method) !== 1) {
|
|
|
|
throw new ArcanistUsageException(
|
2015-02-01 01:05:27 +01:00
|
|
|
pht('Provide exactly one Conduit method name.'));
|
2011-05-06 17:43:38 +02:00
|
|
|
}
|
|
|
|
$method = reset($method);
|
|
|
|
|
2014-05-12 20:36:19 +02:00
|
|
|
$console = PhutilConsole::getConsole();
|
2015-01-02 01:36:24 +01:00
|
|
|
if (!function_exists('posix_isatty') || posix_isatty(STDIN)) {
|
|
|
|
$console->writeErr(
|
|
|
|
"%s\n",
|
|
|
|
pht('Waiting for JSON parameters on stdin...'));
|
|
|
|
}
|
2011-05-06 17:43:38 +02:00
|
|
|
$params = @file_get_contents('php://stdin');
|
2015-05-04 14:28:21 +02:00
|
|
|
try {
|
|
|
|
$params = phutil_json_decode($params);
|
|
|
|
} catch (PhutilJSONParserException $ex) {
|
2011-05-06 17:43:38 +02:00
|
|
|
throw new ArcanistUsageException(
|
2015-02-01 01:05:27 +01:00
|
|
|
pht('Provide method parameters on stdin as a JSON blob.'));
|
2011-05-06 17:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$error = null;
|
|
|
|
$error_message = null;
|
|
|
|
try {
|
|
|
|
$result = $this->getConduit()->callMethodSynchronous(
|
|
|
|
$method,
|
|
|
|
$params);
|
|
|
|
} catch (ConduitClientException $ex) {
|
|
|
|
$error = $ex->getErrorCode();
|
|
|
|
$error_message = $ex->getMessage();
|
|
|
|
$result = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(array(
|
|
|
|
'error' => $error,
|
|
|
|
'errorMessage' => $error_message,
|
|
|
|
'response' => $result,
|
|
|
|
))."\n";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-09 01:12:13 +02:00
|
|
|
|
2011-05-06 17:43:38 +02:00
|
|
|
}
|