Changeset View
Changeset View
Standalone View
Standalone View
src/toolset/command/ArcanistCommand.php
| <?php | <?php | ||||
| final class ArcanistCommand | final class ArcanistCommand | ||||
| extends Phobject { | extends Phobject { | ||||
| private $logEngine; | private $logEngine; | ||||
| private $executableFuture; | private $executableFuture; | ||||
| private $resolveOnError = false; | |||||
| public function setExecutableFuture(PhutilExecutableFuture $future) { | public function setExecutableFuture(PhutilExecutableFuture $future) { | ||||
| $this->executableFuture = $future; | $this->executableFuture = $future; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getExecutableFuture() { | public function getExecutableFuture() { | ||||
| return $this->executableFuture; | return $this->executableFuture; | ||||
| } | } | ||||
| public function setLogEngine(ArcanistLogEngine $log_engine) { | public function setLogEngine(ArcanistLogEngine $log_engine) { | ||||
| $this->logEngine = $log_engine; | $this->logEngine = $log_engine; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getLogEngine() { | public function getLogEngine() { | ||||
| return $this->logEngine; | return $this->logEngine; | ||||
| } | } | ||||
| public function setResolveOnError($resolve_on_error) { | |||||
| $this->resolveOnError = $resolve_on_error; | |||||
| return $this; | |||||
| } | |||||
| public function getResolveOnError() { | |||||
| return $this->resolveOnError; | |||||
| } | |||||
| public function execute() { | public function execute() { | ||||
| $log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
| $future = $this->getExecutableFuture(); | $future = $this->getExecutableFuture(); | ||||
| $command = $future->getCommand(); | $command = $future->getCommand(); | ||||
| $log->writeNewline(); | $log->writeNewline(); | ||||
| $log->writeStatus( | $log->writeStatus( | ||||
| ' $ ', | ' $ ', | ||||
| tsprintf('**%s**', phutil_string_cast($command))); | tsprintf('**%s**', phutil_string_cast($command))); | ||||
| $log->writeNewline(); | $log->writeNewline(); | ||||
| $err = $future->resolve(); | $err = $future->resolve(); | ||||
| $log->writeNewline(); | $log->writeNewline(); | ||||
| if ($err) { | if ($err && !$this->getResolveOnError()) { | ||||
| $log->writeError( | $log->writeError( | ||||
| pht('ERROR'), | pht('ERROR'), | ||||
| pht( | pht( | ||||
| 'Command exited with error code %d.', | 'Command exited with error code %d.', | ||||
| $err)); | $err)); | ||||
| throw new CommandException( | throw new CommandException( | ||||
| pht('Command exited with nonzero error code.'), | pht('Command exited with nonzero error code.'), | ||||
| $command, | $command, | ||||
| $err, | $err, | ||||
| '', | '', | ||||
| ''); | ''); | ||||
| } | } | ||||
| return $err; | |||||
| } | } | ||||
| } | } | ||||