1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 10:42:41 +01:00

Minor bin/aphlict cleanup

Summary: Ref T10697. This just improves a couple of minor `bin/aphlict` things: make argument parsing more explicit/consistent, consolidate a little bit of duplicated code.

Test Plan: Ran all `bin/aphlict` commands.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10697

Differential Revision: https://secure.phabricator.com/D15698
This commit is contained in:
epriestley 2016-04-13 08:51:12 -07:00
parent 7150aa8e19
commit a2588d62e7
6 changed files with 48 additions and 49 deletions

View file

@ -4,17 +4,18 @@ final class PhabricatorAphlictManagementDebugWorkflow
extends PhabricatorAphlictManagementWorkflow { extends PhabricatorAphlictManagementWorkflow {
protected function didConstruct() { protected function didConstruct() {
parent::didConstruct();
$this $this
->setName('debug') ->setName('debug')
->setSynopsis( ->setSynopsis(
pht( pht(
'Start the notifications server in the foreground and print large '. 'Start the notifications server in the foreground and print large '.
'volumes of diagnostic information to the console.')); 'volumes of diagnostic information to the console.'))
->setArguments($this->getLaunchArguments());
} }
public function execute(PhutilArgumentParser $args) { public function execute(PhutilArgumentParser $args) {
parent::execute($args); $this->parseLaunchArguments($args);
$this->setDebug(true); $this->setDebug(true);
$this->willLaunch(); $this->willLaunch();

View file

@ -4,19 +4,20 @@ final class PhabricatorAphlictManagementRestartWorkflow
extends PhabricatorAphlictManagementWorkflow { extends PhabricatorAphlictManagementWorkflow {
protected function didConstruct() { protected function didConstruct() {
parent::didConstruct();
$this $this
->setName('restart') ->setName('restart')
->setSynopsis(pht('Stop, then start the notifications server.')); ->setSynopsis(pht('Stop, then start the notification server.'))
->setArguments($this->getLaunchArguments());
} }
public function execute(PhutilArgumentParser $args) { public function execute(PhutilArgumentParser $args) {
parent::execute($args); $this->parseLaunchArguments($args);
$err = $this->executeStopCommand(); $err = $this->executeStopCommand();
if ($err) { if ($err) {
return $err; return $err;
} }
return $this->executeStartCommand(); return $this->executeStartCommand();
} }

View file

@ -4,14 +4,14 @@ final class PhabricatorAphlictManagementStartWorkflow
extends PhabricatorAphlictManagementWorkflow { extends PhabricatorAphlictManagementWorkflow {
protected function didConstruct() { protected function didConstruct() {
parent::didConstruct();
$this $this
->setName('start') ->setName('start')
->setSynopsis(pht('Start the notifications server.')); ->setSynopsis(pht('Start the notifications server.'))
->setArguments($this->getLaunchArguments());
} }
public function execute(PhutilArgumentParser $args) { public function execute(PhutilArgumentParser $args) {
parent::execute($args); $this->parseLaunchArguments($args);
return $this->executeStartCommand(); return $this->executeStartCommand();
} }

View file

@ -6,7 +6,7 @@ final class PhabricatorAphlictManagementStatusWorkflow
protected function didConstruct() { protected function didConstruct() {
$this $this
->setName('status') ->setName('status')
->setSynopsis(pht('Show the status of the notifications server.')) ->setSynopsis(pht('Show the status of the notification server.'))
->setArguments(array()); ->setArguments(array());
} }

View file

@ -6,7 +6,7 @@ final class PhabricatorAphlictManagementStopWorkflow
protected function didConstruct() { protected function didConstruct() {
$this $this
->setName('stop') ->setName('stop')
->setSynopsis(pht('Stop the notifications server.')) ->setSynopsis(pht('Stop the notification server.'))
->setArguments(array()); ->setArguments(array());
} }

View file

@ -7,27 +7,29 @@ abstract class PhabricatorAphlictManagementWorkflow
private $clientHost; private $clientHost;
private $clientPort; private $clientPort;
protected function didConstruct() { final protected function setDebug($debug) {
$this $this->debug = $debug;
->setArguments( return $this;
array(
array(
'name' => 'client-host',
'param' => 'hostname',
'help' => pht('Hostname to bind to for the client server.'),
),
array(
'name' => 'client-port',
'param' => 'port',
'help' => pht('Port to bind to for the client server.'),
),
));
} }
public function execute(PhutilArgumentParser $args) { protected function getLaunchArguments() {
return array(
array(
'name' => 'client-host',
'param' => 'hostname',
'help' => pht('Hostname to bind to for the client server.'),
),
array(
'name' => 'client-port',
'param' => 'port',
'help' => pht('Port to bind to for the client server.'),
),
);
}
protected function parseLaunchArguments(PhutilArgumentParser $args) {
$this->clientHost = $args->getArg('client-host'); $this->clientHost = $args->getArg('client-host');
$this->clientPort = $args->getArg('client-port'); $this->clientPort = $args->getArg('client-port');
return 0;
} }
final public function getPIDPath() { final public function getPIDPath() {
@ -86,11 +88,6 @@ abstract class PhabricatorAphlictManagementWorkflow
exit(1); exit(1);
} }
final protected function setDebug($debug) {
$this->debug = $debug;
return $this;
}
public static function requireExtensions() { public static function requireExtensions() {
self::mustHaveExtension('pcntl'); self::mustHaveExtension('pcntl');
self::mustHaveExtension('posix'); self::mustHaveExtension('posix');
@ -146,11 +143,8 @@ abstract class PhabricatorAphlictManagementWorkflow
$test_argv = $this->getServerArgv(); $test_argv = $this->getServerArgv();
$test_argv[] = '--test=true'; $test_argv[] = '--test=true';
execx(
'%s %s %Ls', execx('%C', $this->getStartCommand($test_argv));
$this->getNodeBinary(),
$this->getAphlictScriptPath(),
$test_argv);
} }
private function getServerArgv() { private function getServerArgv() {
@ -189,11 +183,6 @@ abstract class PhabricatorAphlictManagementWorkflow
return $server_argv; return $server_argv;
} }
private function getAphlictScriptPath() {
$root = dirname(phutil_get_library_root('phabricator'));
return $root.'/support/aphlict/server/aphlict_server.js';
}
final protected function launch() { final protected function launch() {
$console = PhutilConsole::getConsole(); $console = PhutilConsole::getConsole();
@ -205,11 +194,7 @@ abstract class PhabricatorAphlictManagementWorkflow
Filesystem::writeFile($this->getPIDPath(), getmypid()); Filesystem::writeFile($this->getPIDPath(), getmypid());
} }
$command = csprintf( $command = $this->getStartCommand($this->getServerArgv());
'%s %s %Ls',
$this->getNodeBinary(),
$this->getAphlictScriptPath(),
$this->getServerArgv());
if (!$this->debug) { if (!$this->debug) {
declare(ticks = 1); declare(ticks = 1);
@ -267,7 +252,6 @@ abstract class PhabricatorAphlictManagementWorkflow
fclose(STDOUT); fclose(STDOUT);
fclose(STDERR); fclose(STDERR);
$this->launch(); $this->launch();
return 0; return 0;
} }
@ -325,4 +309,17 @@ abstract class PhabricatorAphlictManagementWorkflow
'$PATH')); '$PATH'));
} }
private function getAphlictScriptPath() {
$root = dirname(phutil_get_library_root('phabricator'));
return $root.'/support/aphlict/server/aphlict_server.js';
}
private function getStartCommand(array $server_argv) {
return csprintf(
'%s %s %Ls',
$this->getNodeBinary(),
$this->getAphlictScriptPath(),
$server_argv);
}
} }