feat(api): Extend a bit IInput and IOutput

Make sure it is somewhat feature complete with the API used in Base.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
pull/62942/head
Carl Schwan 2 weeks ago
parent 1cb708e986
commit cca2ebeaed
No known key found for this signature in database
GPG Key ID: 02325448204E452A
  1. 20
      lib/private/Console/CommandAdapter.php
  2. 20
      lib/private/Console/InputAdapter.php
  3. 38
      lib/private/Console/OutputAdapter.php
  4. 1
      lib/public/Console/Attribute/Argument.php
  5. 1
      lib/public/Console/Attribute/AsCommand.php
  6. 1
      lib/public/Console/Attribute/Option.php
  7. 37
      lib/public/Console/IInput.php
  8. 50
      lib/public/Console/IOutput.php

@ -186,7 +186,7 @@ class CommandAdapter extends Base {
$type = $parameter->getType();
if ($type instanceof \ReflectionNamedType && $type->getName() === IOutput::class) {
$parameters[] = new OutputAdapter($output);
$parameters[] = new OutputAdapter($output, $input, $this);
continue;
}
@ -213,4 +213,22 @@ class CommandAdapter extends Base {
return $result instanceof ExitCode ? $result->value : $result;
}
#[Override]
public function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, iterable $items, string $prefix = ' - '): void {
// To make it public
parent::writeArrayInOutputFormat($input, $output, $items, $prefix);
}
#[Override]
public function writeTableInOutputFormat(InputInterface $input, OutputInterface $output, array $items): void {
// To make it public
parent::writeTableInOutputFormat($input, $output, $items);
}
#[Override]
public function writeStreamingTableInOutputFormat(InputInterface $input, OutputInterface $output, \Iterator $items, int $tableGroupSize): void {
// To make it public
parent::writeStreamingTableInOutputFormat($input, $output, $items, $tableGroupSize);
}
}

@ -26,4 +26,24 @@ class InputAdapter implements IInput {
public function getArgument(string $name): string|bool|int|float|array|null {
return $this->input->getArgument($name);
}
#[Override]
public function hasArgument(string $name): bool {
return $this->input->hasArgument($name);
}
#[Override]
public function getOptions(): array {
return $this->input->getOptions();
}
#[Override]
public function getOption(string $name): string|bool|int|float|array|null {
return $this->input->getOption($name);
}
#[Override]
public function hasOption(string $name): bool {
return $this->input->hasOption($name);
}
}

@ -9,11 +9,14 @@ namespace OC\Console;
use OCP\Console\IOutput;
use Override;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class OutputAdapter implements IOutput {
public function __construct(
public readonly OutputInterface $output,
public readonly InputInterface $input,
public readonly CommandAdapter $commandAdapter,
) {
}
@ -26,4 +29,39 @@ class OutputAdapter implements IOutput {
public function writeln(iterable|string $messages): void {
$this->output->writeln($messages);
}
#[Override]
public function isQuiet(): bool {
return $this->output->isQuiet();
}
#[Override]
public function isVerbose(): bool {
return $this->output->isVerbose();
}
#[Override]
public function isVeryVerbose(): bool {
return $this->output->isVeryVerbose();
}
#[Override]
public function isDebug(): bool {
return $this->output->isDebug();
}
#[Override]
public function writeArrayInOutputFormat(iterable $items, string $prefix = ' - '): void {
$this->commandAdapter->writeArrayInOutputFormat($this->input, $this->output, $items, $prefix);
}
#[Override]
public function writeTableInOutputFormat(array $items): void {
$this->commandAdapter->writeTableInOutputFormat($this->input, $this->output, $items);
}
#[Override]
public function writeStreamingTableInOutputFormat(\Iterator $items, int $tableGroupSize): void {
$this->commandAdapter->writeStreamingTableInOutputFormat($this->input, $this->output, $items, $tableGroupSize);
}
}

@ -63,6 +63,7 @@ final class Argument {
*
* @param string $description The description of the argument, displayed with the help page
* @param string $name The name of the argument
* @since 35.0.0
*/
public function __construct(
public string $description = '',

@ -64,6 +64,7 @@ final class AsCommand {
* @param bool $hidden If true, the command won't be shown when listing all the available commands, but it can still be run as any other command
* @param string|null $help The help content of the command, displayed with the help page
* @param string[] $usages The list of usage examples, displayed with the help page
* @since 35.0.0
*/
public function __construct(
public string $name,

@ -64,6 +64,7 @@ final class Option {
* @param string $description The description of the option, displayed with the help page
* @param string $name The name of the option
* @param array|string|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @since 35.0.0
*/
public function __construct(
public string $description = '',

@ -10,21 +10,54 @@ namespace OCP\Console;
use InvalidArgumentException;
use OCP\AppFramework\Attribute\Consumable;
/**
* Interface that lets you retrieve the input from a command.
*
* @since 35.0.0
*/
#[Consumable(since: '35.0.0')]
interface IInput {
/**
* Returns all the given arguments merged with the default values.
*
* @return array<string|bool|int|float|array|null>
* @since 35.0.0
*/
public function getArguments(): array;
/**
* Returns the argument value for a given argument name.
*
* @return string|bool|int|float|array|null
*
* @throws InvalidArgumentException When argument given doesn't exist
* @since 35.0.0
*/
public function getArgument(string $name): string|bool|int|float|array|null;
/**
* Returns true if an argument exists by name or position.
* @since 35.0.0
*/
public function hasArgument(string $name): bool;
/**
* Returns all the given options merged with the default values.
*
* @return array<string|bool|int|float|array|null>
* @since 35.0.0
*/
public function getOptions(): array;
/**
* Returns the option value for a given option name.
*
* @throws InvalidArgumentException When option given doesn't exist
* @since 35.0.0
*/
public function getOption(string $name): string|bool|int|float|array|null;
/**
* Returns true if an option exists by name.
* @since 35.0.0
*/
public function hasOption(string $name): bool;
}

@ -10,6 +10,8 @@ namespace OCP\Console;
use OCP\AppFramework\Attribute\Consumable;
/**
* Interface that lets you output content from a command.
*
* @since 35.0.0
*/
#[Consumable(since: '35.0.0')]
@ -27,4 +29,52 @@ interface IOutput {
* @since 35.0.0
*/
public function writeln(string|iterable $messages): void;
/**
* Returns whether verbosity is quiet (-q).
* @since 35.0.0
*/
public function isQuiet() : bool;
/**
* Returns whether verbosity is verbose (-v).
* @since 35.0.0
*/
public function isVerbose() : bool;
/**
* Returns whether verbosity is very verbose (-vv).
* @since 35.0.0
*/
public function isVeryVerbose() : bool;
/**
* Returns whether verbosity is debug (-vvv).
* @since 35.0.0
*/
public function isDebug() : bool;
/**
* Write a list of items in the format specified with --output
*
* @param list<string> $items
* @since 35.0.0
*/
public function writeArrayInOutputFormat(iterable $items, string $prefix = ' - '): void;
/**
* Write a multidimensional array of items in the format specified with --output
*
* @param list<array<string, mixed>> $items
* @since 35.0.0
*/
public function writeTableInOutputFormat(array $items): void;
/**
* Write a multidimensional iterator of items in the format specified with --output
*
* @param \Iterator<array<string, mixed>> $items
* @since 35.0.0
*/
public function writeStreamingTableInOutputFormat(\Iterator $items, int $tableGroupSize): void;
}

Loading…
Cancel
Save