use table helper

This commit is contained in:
Uwe Steinmann 2025-11-13 17:58:48 +01:00
parent 98cb3b042d
commit 799b870f9a

View File

@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Helper\Table;
use Seeddms\Seeddms\Settings; use Seeddms\Seeddms\Settings;
use Seeddms\Seeddms\Translator; use Seeddms\Seeddms\Translator;
@ -51,6 +52,7 @@ class ListcacheCommand extends Command
$cachedir = $settings->_cacheDir; $cachedir = $settings->_cacheDir;
$totalc = 0; $totalc = 0;
$totalspace = 0; $totalspace = 0;
$tabledata = [];
// Preview for png, pdf, and txt */ // Preview for png, pdf, and txt */
foreach(['png', 'pdf', 'txt'] as $t) { foreach(['png', 'pdf', 'txt'] as $t) {
$path = addDirSep($cachedir).$t; $path = addDirSep($cachedir).$t;
@ -63,7 +65,8 @@ class ListcacheCommand extends Command
} }
$totalc += $c; $totalc += $c;
$totalspace += $space; $totalspace += $space;
$output->writeln(sprintf($outformat, 'preview'.$t, $translator->translate('preview_'.$t), SeedDMS_Core_File::format_filesize($space), $c)); // $output->writeln(sprintf($outformat, 'preview'.$t, $translator->translate('preview_'.$t), SeedDMS_Core_File::format_filesize($space), $c));
$tabledata[] = ['preview'.$t, $translator->translate('preview_'.$t), SeedDMS_Core_File::format_filesize($space), $c];
} }
/* Javascript */ /* Javascript */
@ -77,7 +80,8 @@ class ListcacheCommand extends Command
} }
$totalc += $c; $totalc += $c;
$totalspace += $space; $totalspace += $space;
$output->writeln(sprintf($outformat, 'js', $translator->translate('temp_jscode'), SeedDMS_Core_File::format_filesize($space), $c)); // $output->writeln(sprintf($outformat, 'js', $translator->translate('temp_jscode'), SeedDMS_Core_File::format_filesize($space), $c));
$tabledata[] = ['js', $translator->translate('temp_jscode'), SeedDMS_Core_File::format_filesize($space), $c];
$caches = []; $caches = [];
/* Create a dummy view for passing it to additionalCache() */ /* Create a dummy view for passing it to additionalCache() */
@ -90,8 +94,14 @@ class ListcacheCommand extends Command
} }
} }
foreach($caches as $cache) { foreach($caches as $cache) {
$output->writeln(sprintf($outformat, $cache[0], $cache[1], SeedDMS_Core_File::format_filesize($cache[2]), $cache[3])); // $output->writeln(sprintf($outformat, $cache[0], $cache[1], SeedDMS_Core_File::format_filesize($cache[2]), $cache[3]));
$tabledata[] = [$cache[0], $cache[1], SeedDMS_Core_File::format_filesize($cache[2]), $cache[3]];
} }
$table = new Table($output);
$table
->setHeaders(['Cache', 'Name', 'Size', 'Count'])
->setRows($tabledata);
$table->render();
// print_r($caches); // print_r($caches);
return Command::SUCCESS; return Command::SUCCESS;