35 lines
789 B
PHP
35 lines
789 B
PHP
<?php
|
|
namespace nur\m\cli;
|
|
|
|
use nur\A;
|
|
use nur\cli\Application;
|
|
use nur\config;
|
|
use nur\iter;
|
|
|
|
/**
|
|
* Class ConndevApp: afficher la commande pour se connecter à une base de
|
|
* données mysql en développement
|
|
*/
|
|
class ConndevApp extends Application {
|
|
private $args;
|
|
|
|
public function main() {
|
|
$ip = A::get($this->args, 0);
|
|
if (!$ip) $ip = "NOT-FOUND";
|
|
|
|
$dbs = config::get("dbs");
|
|
$db = A::get($this->args, 1);
|
|
if ($db === null) {
|
|
$db = iter::first_key($dbs);
|
|
} elseif (preg_match('/^[0-9]+$/', $db)) {
|
|
$db = array_keys($dbs)[$db];
|
|
}
|
|
|
|
if (isset($dbs[$db])) {
|
|
$db = $dbs[$db];
|
|
preg_match("/dbname=([a-zA-Z0-9_]+)/", $db["name"], $ms);
|
|
$dbname = $ms[1];
|
|
echo "mysql -u$db[user] -p$db[pass] -h$ip $dbname\n";
|
|
}
|
|
}
|
|
} |