mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add a ./bin/storage shell
command
Summary: Fixes T7078. Adds a `./bin/storage shell` command which passes through to a MySQL shell. This is slightly more convenient than running `mysql` manually. Test Plan: Ran `./bin/storage shell` and got a MySQL shell. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7078 Differential Revision: https://secure.phabricator.com/D11548
This commit is contained in:
parent
7ed4bb4f17
commit
1ecfa0313c
4 changed files with 55 additions and 16 deletions
|
@ -2462,6 +2462,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorStorageManagementDumpWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php',
|
'PhabricatorStorageManagementDumpWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php',
|
||||||
'PhabricatorStorageManagementProbeWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementProbeWorkflow.php',
|
'PhabricatorStorageManagementProbeWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementProbeWorkflow.php',
|
||||||
'PhabricatorStorageManagementQuickstartWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementQuickstartWorkflow.php',
|
'PhabricatorStorageManagementQuickstartWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementQuickstartWorkflow.php',
|
||||||
|
'PhabricatorStorageManagementShellWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementShellWorkflow.php',
|
||||||
'PhabricatorStorageManagementStatusWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php',
|
'PhabricatorStorageManagementStatusWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php',
|
||||||
'PhabricatorStorageManagementUpgradeWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php',
|
'PhabricatorStorageManagementUpgradeWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php',
|
||||||
'PhabricatorStorageManagementWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php',
|
'PhabricatorStorageManagementWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php',
|
||||||
|
@ -5753,6 +5754,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorStorageManagementDumpWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
'PhabricatorStorageManagementDumpWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
||||||
'PhabricatorStorageManagementProbeWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
'PhabricatorStorageManagementProbeWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
||||||
'PhabricatorStorageManagementQuickstartWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
'PhabricatorStorageManagementQuickstartWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
||||||
|
'PhabricatorStorageManagementShellWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
||||||
'PhabricatorStorageManagementStatusWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
'PhabricatorStorageManagementStatusWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
||||||
'PhabricatorStorageManagementUpgradeWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
'PhabricatorStorageManagementUpgradeWorkflow' => 'PhabricatorStorageManagementWorkflow',
|
||||||
'PhabricatorStorageManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
'PhabricatorStorageManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||||
|
|
|
@ -32,7 +32,6 @@ final class PhabricatorStorageManagementDumpWorkflow
|
||||||
list($host, $port) = $this->getBareHostAndPort($api->getHost());
|
list($host, $port) = $this->getBareHostAndPort($api->getHost());
|
||||||
|
|
||||||
$flag_password = '';
|
$flag_password = '';
|
||||||
|
|
||||||
$password = $api->getPassword();
|
$password = $api->getPassword();
|
||||||
if ($password) {
|
if ($password) {
|
||||||
if (strlen($password->openEnvelope())) {
|
if (strlen($password->openEnvelope())) {
|
||||||
|
@ -54,19 +53,4 @@ final class PhabricatorStorageManagementDumpWorkflow
|
||||||
$databases);
|
$databases);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBareHostAndPort($host) {
|
|
||||||
// Split out port information, since the command-line client requires a
|
|
||||||
// separate flag for the port.
|
|
||||||
$uri = new PhutilURI('mysql://'.$host);
|
|
||||||
if ($uri->getPort()) {
|
|
||||||
$port = $uri->getPort();
|
|
||||||
$bare_hostname = $uri->getDomain();
|
|
||||||
} else {
|
|
||||||
$port = null;
|
|
||||||
$bare_hostname = $host;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($bare_hostname, $port);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorStorageManagementShellWorkflow
|
||||||
|
extends PhabricatorStorageManagementWorkflow {
|
||||||
|
|
||||||
|
protected function didConstruct() {
|
||||||
|
$this
|
||||||
|
->setName('shell')
|
||||||
|
->setExamples('**shell** [__options__]')
|
||||||
|
->setSynopsis('Launch an interactive shell.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(PhutilArgumentParser $args) {
|
||||||
|
$api = $this->getAPI();
|
||||||
|
list($host, $port) = $this->getBareHostAndPort($api->getHost());
|
||||||
|
|
||||||
|
$flag_port = $port
|
||||||
|
? csprintf('--port %d', $port)
|
||||||
|
: '';
|
||||||
|
|
||||||
|
$flag_password = '';
|
||||||
|
$password = $api->getPassword();
|
||||||
|
if ($password) {
|
||||||
|
if (strlen($password->openEnvelope())) {
|
||||||
|
$flag_password = csprintf('--password=%P', $password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return phutil_passthru(
|
||||||
|
'mysql --default-character-set=utf8 '.
|
||||||
|
'-u %s %C -h %s %C',
|
||||||
|
$api->getUser(),
|
||||||
|
$flag_password,
|
||||||
|
$host,
|
||||||
|
$flag_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -663,4 +663,19 @@ abstract class PhabricatorStorageManagementWorkflow
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final function getBareHostAndPort($host) {
|
||||||
|
// Split out port information, since the command-line client requires a
|
||||||
|
// separate flag for the port.
|
||||||
|
$uri = new PhutilURI('mysql://'.$host);
|
||||||
|
if ($uri->getPort()) {
|
||||||
|
$port = $uri->getPort();
|
||||||
|
$bare_hostname = $uri->getDomain();
|
||||||
|
} else {
|
||||||
|
$port = null;
|
||||||
|
$bare_hostname = $host;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array($bare_hostname, $port);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue