@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+48 -49
+4 -3
src/applications/aphlict/management/PhabricatorAphlictManagementDebugWorkflow.php
··· 4 4 extends PhabricatorAphlictManagementWorkflow { 5 5 6 6 protected function didConstruct() { 7 - parent::didConstruct(); 8 7 $this 9 8 ->setName('debug') 10 9 ->setSynopsis( 11 10 pht( 12 11 'Start the notifications server in the foreground and print large '. 13 - 'volumes of diagnostic information to the console.')); 12 + 'volumes of diagnostic information to the console.')) 13 + ->setArguments($this->getLaunchArguments()); 14 14 } 15 15 16 16 public function execute(PhutilArgumentParser $args) { 17 - parent::execute($args); 17 + $this->parseLaunchArguments($args); 18 + 18 19 $this->setDebug(true); 19 20 20 21 $this->willLaunch();
+4 -3
src/applications/aphlict/management/PhabricatorAphlictManagementRestartWorkflow.php
··· 4 4 extends PhabricatorAphlictManagementWorkflow { 5 5 6 6 protected function didConstruct() { 7 - parent::didConstruct(); 8 7 $this 9 8 ->setName('restart') 10 - ->setSynopsis(pht('Stop, then start the notifications server.')); 9 + ->setSynopsis(pht('Stop, then start the notification server.')) 10 + ->setArguments($this->getLaunchArguments()); 11 11 } 12 12 13 13 public function execute(PhutilArgumentParser $args) { 14 - parent::execute($args); 14 + $this->parseLaunchArguments($args); 15 15 16 16 $err = $this->executeStopCommand(); 17 17 if ($err) { 18 18 return $err; 19 19 } 20 + 20 21 return $this->executeStartCommand(); 21 22 } 22 23
+3 -3
src/applications/aphlict/management/PhabricatorAphlictManagementStartWorkflow.php
··· 4 4 extends PhabricatorAphlictManagementWorkflow { 5 5 6 6 protected function didConstruct() { 7 - parent::didConstruct(); 8 7 $this 9 8 ->setName('start') 10 - ->setSynopsis(pht('Start the notifications server.')); 9 + ->setSynopsis(pht('Start the notifications server.')) 10 + ->setArguments($this->getLaunchArguments()); 11 11 } 12 12 13 13 public function execute(PhutilArgumentParser $args) { 14 - parent::execute($args); 14 + $this->parseLaunchArguments($args); 15 15 return $this->executeStartCommand(); 16 16 } 17 17
+1 -1
src/applications/aphlict/management/PhabricatorAphlictManagementStatusWorkflow.php
··· 6 6 protected function didConstruct() { 7 7 $this 8 8 ->setName('status') 9 - ->setSynopsis(pht('Show the status of the notifications server.')) 9 + ->setSynopsis(pht('Show the status of the notification server.')) 10 10 ->setArguments(array()); 11 11 } 12 12
+1 -1
src/applications/aphlict/management/PhabricatorAphlictManagementStopWorkflow.php
··· 6 6 protected function didConstruct() { 7 7 $this 8 8 ->setName('stop') 9 - ->setSynopsis(pht('Stop the notifications server.')) 9 + ->setSynopsis(pht('Stop the notification server.')) 10 10 ->setArguments(array()); 11 11 } 12 12
+35 -38
src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php
··· 7 7 private $clientHost; 8 8 private $clientPort; 9 9 10 - protected function didConstruct() { 11 - $this 12 - ->setArguments( 13 - array( 14 - array( 15 - 'name' => 'client-host', 16 - 'param' => 'hostname', 17 - 'help' => pht('Hostname to bind to for the client server.'), 18 - ), 19 - array( 20 - 'name' => 'client-port', 21 - 'param' => 'port', 22 - 'help' => pht('Port to bind to for the client server.'), 23 - ), 24 - )); 10 + final protected function setDebug($debug) { 11 + $this->debug = $debug; 12 + return $this; 25 13 } 26 14 27 - public function execute(PhutilArgumentParser $args) { 15 + protected function getLaunchArguments() { 16 + return array( 17 + array( 18 + 'name' => 'client-host', 19 + 'param' => 'hostname', 20 + 'help' => pht('Hostname to bind to for the client server.'), 21 + ), 22 + array( 23 + 'name' => 'client-port', 24 + 'param' => 'port', 25 + 'help' => pht('Port to bind to for the client server.'), 26 + ), 27 + ); 28 + } 29 + 30 + protected function parseLaunchArguments(PhutilArgumentParser $args) { 28 31 $this->clientHost = $args->getArg('client-host'); 29 32 $this->clientPort = $args->getArg('client-port'); 30 - return 0; 31 33 } 32 34 33 35 final public function getPIDPath() { ··· 86 88 exit(1); 87 89 } 88 90 89 - final protected function setDebug($debug) { 90 - $this->debug = $debug; 91 - return $this; 92 - } 93 - 94 91 public static function requireExtensions() { 95 92 self::mustHaveExtension('pcntl'); 96 93 self::mustHaveExtension('posix'); ··· 146 143 $test_argv = $this->getServerArgv(); 147 144 $test_argv[] = '--test=true'; 148 145 149 - execx( 150 - '%s %s %Ls', 151 - $this->getNodeBinary(), 152 - $this->getAphlictScriptPath(), 153 - $test_argv); 146 + 147 + execx('%C', $this->getStartCommand($test_argv)); 154 148 } 155 149 156 150 private function getServerArgv() { ··· 189 183 return $server_argv; 190 184 } 191 185 192 - private function getAphlictScriptPath() { 193 - $root = dirname(phutil_get_library_root('phabricator')); 194 - return $root.'/support/aphlict/server/aphlict_server.js'; 195 - } 196 - 197 186 final protected function launch() { 198 187 $console = PhutilConsole::getConsole(); 199 188 ··· 205 194 Filesystem::writeFile($this->getPIDPath(), getmypid()); 206 195 } 207 196 208 - $command = csprintf( 209 - '%s %s %Ls', 210 - $this->getNodeBinary(), 211 - $this->getAphlictScriptPath(), 212 - $this->getServerArgv()); 197 + $command = $this->getStartCommand($this->getServerArgv()); 213 198 214 199 if (!$this->debug) { 215 200 declare(ticks = 1); ··· 266 251 // in another script using passthru().) 267 252 fclose(STDOUT); 268 253 fclose(STDERR); 269 - 270 254 271 255 $this->launch(); 272 256 return 0; ··· 323 307 'nodejs', 324 308 'node', 325 309 '$PATH')); 310 + } 311 + 312 + private function getAphlictScriptPath() { 313 + $root = dirname(phutil_get_library_root('phabricator')); 314 + return $root.'/support/aphlict/server/aphlict_server.js'; 315 + } 316 + 317 + private function getStartCommand(array $server_argv) { 318 + return csprintf( 319 + '%s %s %Ls', 320 + $this->getNodeBinary(), 321 + $this->getAphlictScriptPath(), 322 + $server_argv); 326 323 } 327 324 328 325 }