Nextcloud PHP API (master)

AsCommand
in package

FinalYes

Attribute to declare that the class is a command.

Can be used either on a class:

#[AsCommand(
     name: 'app:create-user',
     // this short description is shown when running "occ list"
     description: 'Creates a new user.',
     // this is shown when running the command with the "--help" option
     help: 'This command allows you to create a user...',
     // this allows you to show one or more usage examples (no need to add the command name)
     usages: ['bob', 'alice --as-admin'],
)]
class CreateUserCommand {
    public function __invoke(): ExitCode {
        // ...
        return ExitCode::Success;
    }
}

Or on methods:

class UserCommands {
    #[AsCommand('app:user:create')]
    public function create(IOutput $output): ExitCode {
        // ...

        return ExitCode::Success;
    }

    #[AsCommand('app:user:delete')]
    public function delete(IOutput $output): int
    {
        // ...

        return ExitCode::Success;
    }
}
Tags
since
35.0.0
Attributes
#[Attribute]
\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD
#[Consumable]
$since: '35.0.0'

Table of Contents

Properties

$description  : string|null
$help  : string|null
$hidden  : bool
$name  : string
$supportsOutputFormat  : bool
$usages  : array<string|int, mixed>

Methods

__construct()  : mixed

Properties

$description

public string|null $description = null

$supportsOutputFormat

public bool $supportsOutputFormat = false

$usages

public array<string|int, mixed> $usages = []

Methods

__construct()

public __construct(string $name[, string|null $description = null ][, string|null $help = null ][, array<string|int, string> $usages = [] ][, bool $hidden = false ][, bool $supportsOutputFormat = false ]) : mixed
Parameters
$name : string

The name of the command, used when calling it (i.e. "cache:clear")

$description : string|null = null

The description of the command, displayed with the help page

$help : string|null = null

The help content of the command, displayed with the help page

$usages : array<string|int, string> = []

The list of usage examples, displayed with the help page

$hidden : bool = false

If true, the command won't be shown when listing all the available commands, but it can still be run as any other command

$supportsOutputFormat : bool = false

If true, the command can output the result in JSON

Tags
since
35.0.0
On this page

Search results