diff --git a/src/Command/Group/GroupFindCommand.php b/src/Command/Group/GroupFindCommand.php index 46dad70..4362746 100644 --- a/src/Command/Group/GroupFindCommand.php +++ b/src/Command/Group/GroupFindCommand.php @@ -2,6 +2,7 @@ namespace SlotDb\Cli\Command\Group; +use SlotDb\Cli\Tool\Format; use SlotDb\Client\SlotDbClient; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -44,12 +45,7 @@ class GroupFindCommand extends Command foreach ($keys as $key) { $row[] = isset($group[$key]) ? $group[$key] : null; } - $row = array_map(fn($v) => match(true) { - is_bool($v) => "".($v?"true":"false")."", - is_int($v) => "{$v}", - is_string($v) => "{$v}", - default => $v, - }, $row); + $row = array_map(Format::formatValue(...), $row); $table->addRow($row); } diff --git a/src/Command/Slot/SlotFindCommand.php b/src/Command/Slot/SlotFindCommand.php index 06e715f..315431c 100644 --- a/src/Command/Slot/SlotFindCommand.php +++ b/src/Command/Slot/SlotFindCommand.php @@ -2,6 +2,7 @@ namespace SlotDb\Cli\Command\Slot; +use SlotDb\Cli\Tool\Format; use SlotDb\Client\SlotDbClient; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -57,12 +58,7 @@ class SlotFindCommand extends Command foreach ($keys as $key) { $row[] = isset($slot[$key]) ? $slot[$key] : null; } - $row = array_map(fn($v) => match(true) { - is_bool($v) => "".($v?"true":"false")."", - is_int($v) => "{$v}", - is_string($v) => "{$v}", - default => $v, - }, $row); + $row = array_map(Format::formatValue(...), $row); $table->addRow($row); } diff --git a/src/Command/Slot/SlotQueryCommand.php b/src/Command/Slot/SlotQueryCommand.php index 1bd46df..bac488b 100644 --- a/src/Command/Slot/SlotQueryCommand.php +++ b/src/Command/Slot/SlotQueryCommand.php @@ -2,6 +2,7 @@ namespace SlotDb\Cli\Command\Slot; +use SlotDb\Cli\Tool\Format; use SlotDb\Client\SlotDbClient; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -42,9 +43,9 @@ class SlotQueryCommand extends Command $output->writeln( sprintf( str_starts_with($k,"_") - ? "%{$len}s: %s" - : "%{$len}s: %s", - $k, json_encode($v) + ? "%{$len}s: %s" + : "%{$len}s: %s", + $k, Format::formatValue($v) ) ); } diff --git a/src/Tool/Format.php b/src/Tool/Format.php new file mode 100644 index 0000000..b56c066 --- /dev/null +++ b/src/Tool/Format.php @@ -0,0 +1,26 @@ + + "[". + join(",", array_map(Format::formatValue(...), $v)). + "](".count($v).")", + is_bool($v) => + "".($v?"true":"false")."", + is_int($v) => + "{$v}", + is_string($v) => + "{$v}", + is_null($v) => + "null", + default => + $v, + }; + } +} \ No newline at end of file