mirror of
https://github.com/nextcloud/server.git
synced 2026-10-25 12:15:44 +01:00
wires suggestedValues into both the legacy stecman _completion hook and Symfony's native _complete/completion path, supporting static lists and dynamic (static or instance-method) callables Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
namespace OCP\Console\Attribute;
|
|
|
|
use OCP\AppFramework\Attribute\Consumable;
|
|
|
|
/**
|
|
* Represents a console command <argument> definition.
|
|
*
|
|
* Can be used in the parameters of the invoke method.
|
|
*
|
|
* ```
|
|
* #[AsCommand(name: 'app:user:created')
|
|
* class CreateUserCommand {
|
|
* public function __invoke(
|
|
* #[Argument(description: "The username of the user")] string $userId,
|
|
* IOutput $output,
|
|
* ): ExitCode {
|
|
* // ...
|
|
* return ExitCode::Success;
|
|
* }
|
|
* }
|
|
* ```
|
|
*
|
|
* Or on methods parameters:
|
|
*
|
|
* ```
|
|
* class UserCommands {
|
|
* #[AsCommand('app:user:create')]
|
|
* public function create(
|
|
* #[Argument(description: "The username of the user")] string $userId,
|
|
* IOutput $output,
|
|
* ): ExitCode {
|
|
* // ...
|
|
*
|
|
* return ExitCode::Success;
|
|
* }
|
|
*
|
|
* #[AsCommand('app:user:delete')]
|
|
* public function delete(
|
|
* #[Argument(description: "The username of the user")] string $userId,
|
|
* IOutput $output,
|
|
* ): ExitCode {
|
|
* // ...
|
|
*
|
|
* return ExitCode::Success;
|
|
* }
|
|
* }
|
|
* ```
|
|
*
|
|
* @since 35.0.0
|
|
*/
|
|
#[\Attribute(\Attribute::TARGET_PARAMETER)]
|
|
#[Consumable(since: '35.0.0')]
|
|
final class Argument {
|
|
/**
|
|
* If unset, the `name` value will be inferred from the parameter definition.
|
|
*
|
|
* @param string $description The description of the argument, displayed with the help page
|
|
* @param string $name The name of the argument
|
|
* @param array|\Closure $suggestedValues A static list of suggestions, or a callable array [ClassName::class, 'method']
|
|
* for dynamic ones (attribute arguments cannot be closures). The method takes
|
|
* the partial value and returns suggestions; non-static methods are called on
|
|
* an instance so they can use constructor-injected services.
|
|
* @since 35.0.0
|
|
*/
|
|
public function __construct(
|
|
public string $description = '',
|
|
public string $name = '',
|
|
public array|\Closure $suggestedValues = [],
|
|
) {
|
|
}
|
|
}
|