diff --git a/scripts/arcanist.php b/scripts/arcanist.php index c48e5c1e..18109e85 100755 --- a/scripts/arcanist.php +++ b/scripts/arcanist.php @@ -26,31 +26,41 @@ ini_set('memory_limit', -1); $original_argv = $argv; $args = new PhutilArgumentParser($argv); $args->parseStandardArguments(); +$args->parsePartial( + array( + array( + 'name' => 'load-phutil-library', + 'param' => 'path', + 'help' => 'Load a libphutil library.', + 'repeat' => true, + ), + array( + 'name' => 'conduit-uri', + 'param' => 'uri', + 'help' => 'Connect to Phabricator install specified by __uri__.', + ), + array( + 'name' => 'conduit-version', + 'param' => 'version', + 'help' => '(Developers) Mock client version in protocol handshake.', + ), + array( + 'name' => 'conduit-timeout', + 'param' => 'timeout', + 'help' => 'Set Conduit timeout (in seconds).', + ), + )); -$argv = $args->getUnconsumedArgumentVector(); $config_trace_mode = $args->getArg('trace'); -$force_conduit = null; -$force_conduit_version = null; -$args = $argv; -$load = array(); -$matches = null; -foreach ($args as $key => $arg) { - if ($arg == '--') { - break; - } else if (preg_match('/^--load-phutil-library=(.*)$/', $arg, $matches)) { - unset($args[$key]); - $load[] = $matches[1]; - } else if (preg_match('/^--conduit-uri=(.*)$/', $arg, $matches)) { - unset($args[$key]); - $force_conduit = $matches[1]; - } else if (preg_match('/^--conduit-version=(.*)$/', $arg, $matches)) { - unset($args[$key]); - $force_conduit_version = $matches[1]; - } -} +$force_conduit = $args->getArg('conduit-uri'); +$force_conduit_version = $args->getArg('conduit-version'); +$conduit_timeout = $args->getArg('conduit-timeout'); +$load = $args->getArg('load-phutil-library'); + +$argv = $args->getUnconsumedArgumentVector(); +$args = array_values($argv); -$args = array_values($args); $working_directory = getcwd(); try { @@ -170,6 +180,9 @@ try { if ($force_conduit_version) { $workflow->forceConduitVersion($force_conduit_version); } + if ($conduit_timeout) { + $workflow->setConduitTimeout($conduit_timeout); + } $need_working_copy = $workflow->requiresWorkingCopy(); $need_conduit = $workflow->requiresConduit(); @@ -289,7 +302,7 @@ try { } echo phutil_console_format( - "\n**Exception:**\n%s\n%s\n", + "**Exception**\n%s\n%s\n", $ex->getMessage(), "(Run with --trace for a full exception trace.)"); diff --git a/src/workflow/ArcanistBaseWorkflow.php b/src/workflow/ArcanistBaseWorkflow.php index 0193a2bf..d97ffaaf 100644 --- a/src/workflow/ArcanistBaseWorkflow.php +++ b/src/workflow/ArcanistBaseWorkflow.php @@ -57,6 +57,7 @@ abstract class ArcanistBaseWorkflow { private $conduitCredentials; private $conduitAuthenticated; private $forcedConduitVersion; + private $conduitTimeout; private $userPHID; private $userName; @@ -146,6 +147,10 @@ abstract class ArcanistBaseWorkflow { $this->conduit = new ConduitClient($this->conduitURI); + if ($this->conduitTimeout) { + $this->conduit->setTimeout($this->conduitTimeout); + } + return $this; } @@ -179,15 +184,54 @@ abstract class ArcanistBaseWorkflow { return $this; } + + /** + * Force arc to identify with a specific Conduit version during the + * protocol handshake. This is primarily useful for development (especially + * for sending diffs which bump the client Conduit version), since the client + * still actually speaks the builtin version of the protocol. + * + * Controlled by the --conduit-version flag. + * + * @param int Version the client should pretend to be. + * @return this + * @task conduit + */ public function forceConduitVersion($version) { $this->forcedConduitVersion = $version; return $this; } + + /** + * Get the protocol version the client should identify with. + * + * @return int Version the client should claim to be. + * @task conduit + */ public function getConduitVersion() { return nonempty($this->forcedConduitVersion, 5); } + + /** + * Override the default timeout for Conduit. + * + * Controlled by the --conduit-timeout flag. + * + * @param float Timeout, in seconds. + * @return this + * @task conduit + */ + public function setConduitTimeout($timeout) { + $this->conduitTimeout = $timeout; + if ($this->conduit) { + $this->conduit->setConduitTimeout($timeout); + } + return $this; + } + + /** * Open and authenticate a conduit connection to a Phabricator server using * provided credentials. Normally, Arcanist does this for you automatically @@ -307,7 +351,7 @@ abstract class ArcanistBaseWorkflow { * @task conduit */ final protected function isConduitAuthenticated() { - return (bool) $this->conduitAuthenticated; + return (bool)$this->conduitAuthenticated; } diff --git a/src/workflow/ArcanistHelpWorkflow.php b/src/workflow/ArcanistHelpWorkflow.php index a9c00b4c..5884fc4f 100644 --- a/src/workflow/ArcanistHelpWorkflow.php +++ b/src/workflow/ArcanistHelpWorkflow.php @@ -195,15 +195,17 @@ EOTEXT Ignore libraries listed in .arcconfig and explicitly load specified libraries instead. Mostly useful for Arcanist development. - __--conduit-uri=...__ + __--conduit-uri__ __uri__ Ignore configured Conduit URI and use an explicit one instead. Mostly useful for Arcanist development. - __--conduit-version=...__ + __--conduit-version__ __version__ Ignore software version and claim to be running some other version instead. Mostly useful for Arcanist development. May cause bad things to happen. + __--conduit-timeout__ __timeout__ + Override the default Conduit timeout. Specified in seconds. EOTEXT );