Multiple fixes

* PDO shell improvements: .query command, -r and --db on command
  line to read commands from file or preselect database.
* Updated build scripts and readme
This commit is contained in:
2021-12-16 16:01:17 +01:00
parent 16753e1892
commit 0c7fc0196a
8 changed files with 126 additions and 59 deletions

View File

@ -15,12 +15,29 @@ class PdoShellCommand extends Command {
protected function configure() {
$this->setName("pdo:shell");
$this->setDescription("Launch an interactive PDO shell");
$this->addOption("db", null, InputOption::VALUE_REQUIRED, "Select database resource", "db");
$this->addOption("read", "r", InputOption::VALUE_REQUIRED, "Read commands to execute from file");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$shell = new Shell\PdoShell($output);
$shell->run();
$db = $input->getOption("db");
$read = $input->getOption("read");
if ($read) {
if (!file_exists($read)) {
$output->writeln("<error>File not found: {$read}</>");
return Command::FAILURE;
}
$file = file($read, FILE_IGNORE_NEW_LINES);
$shell->runCommands($file);
} else {
$shell->runCommands([ ".select {$db}" ]);
$shell->run();
}
return Command::SUCCESS;
}