Plugin fixes

* Added vertical rendering to com.noccy.pdo.shell
* Added missing Log classes for com.noccy.apiclient
This commit is contained in:
2021-12-22 03:03:16 +01:00
parent 80c7c894ab
commit 9050c74a08
4 changed files with 246 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace SparkPlug\Com\Noccy\Pdo\Shell\Shell;
use Attribute;
use SparkPlug\Com\Noccy\Pdo\PdoResource;
use Spark\Commands\Command;
use Spark\SparkApplication;
@ -28,6 +29,7 @@ class PdoShell {
private ?array $lastQuery = null;
#[EnumSetting('output', [ 'table', 'vertical', 'dump' ])]
private array $defaultOptions = [
'output' => 'table',
'table.maxwidth' => 40,
@ -338,5 +340,31 @@ class PdoShell {
$table->render();
}
private function dumpQueryVertical(array $res)
{
if (count($res) == 0) return;
$names = array_keys(reset($res));
$nameWidth = max(array_map("strlen", $names)) + 4;
foreach ($res as $row) {
foreach ($row as $k=>$v) {
$this->output->writeln(
sprintf("<info>%{$nameWidth}s</>: %s",$k, $v)
);
}
if ($row != end($res)) {
$this->output->writeln(str_repeat("-", $nameWidth));
}
}
}
}
#[Attribute(Attribute::TARGET_PROPERTY)]
class EnumSetting
{
public function __construct(string $property, array $valid)
{
}
}