summaryrefslogtreecommitdiffstats
path: root/core/Command/Base.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/Base.php')
-rw-r--r--core/Command/Base.php45
1 files changed, 27 insertions, 18 deletions
diff --git a/core/Command/Base.php b/core/Command/Base.php
index 029942c0673..abf9f95773a 100644
--- a/core/Command/Base.php
+++ b/core/Command/Base.php
@@ -26,9 +26,10 @@
namespace OC\Core\Command;
use OC\Core\Command\User\ListCommand;
-use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
+use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
@@ -38,13 +39,9 @@ class Base extends Command implements CompletionAwareInterface {
public const OUTPUT_FORMAT_JSON = 'json';
public const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty';
- protected $defaultOutputFormat = self::OUTPUT_FORMAT_PLAIN;
-
- /** @var boolean */
- private $php_pcntl_signal = false;
-
- /** @var boolean */
- private $interrupted = false;
+ protected string $defaultOutputFormat = self::OUTPUT_FORMAT_PLAIN;
+ private bool $php_pcntl_signal = false;
+ private bool $interrupted = false;
protected function configure() {
$this
@@ -58,13 +55,7 @@ class Base extends Command implements CompletionAwareInterface {
;
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @param array $items
- * @param string $prefix
- */
- protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') {
+ protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, array $items, string $prefix = ' - '): void {
switch ($input->getOption('output')) {
case self::OUTPUT_FORMAT_JSON:
$output->writeln(json_encode($items));
@@ -94,9 +85,27 @@ class Base extends Command implements CompletionAwareInterface {
}
}
+ protected function writeTableInOutputFormat(InputInterface $input, OutputInterface $output, array $items): void {
+ switch ($input->getOption('output')) {
+ case self::OUTPUT_FORMAT_JSON:
+ $output->writeln(json_encode($items));
+ break;
+ case self::OUTPUT_FORMAT_JSON_PRETTY:
+ $output->writeln(json_encode($items, JSON_PRETTY_PRINT));
+ break;
+ default:
+ $table = new Table($output);
+ $table->setRows($items);
+ if (!empty($items) && is_string(array_key_first(reset($items)))) {
+ $table->setHeaders(array_keys(reset($items)));
+ }
+ $table->render();
+ break;
+ }
+ }
+
+
/**
- * @param InputInterface $input
- * @param OutputInterface $output
* @param mixed $item
*/
protected function writeMixedInOutputFormat(InputInterface $input, OutputInterface $output, $item) {
@@ -118,7 +127,7 @@ class Base extends Command implements CompletionAwareInterface {
}
}
- protected function valueToString($value, $returnNull = true) {
+ protected function valueToString($value, bool $returnNull = true): ?string {
if ($value === false) {
return 'false';
} elseif ($value === true) {