Skip to content

Command API in OCP - #62942

Open
CarlSchwan wants to merge 5 commits into
masterfrom
carl/ocp-console
Open

Command API in OCP#62942
CarlSchwan wants to merge 5 commits into
masterfrom
carl/ocp-console

Conversation

@CarlSchwan

@CarlSchwan CarlSchwan commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

Inspired by the new API from symfony/console

This will allow us to remove all our ugly stubs in many apps.

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(
        #[Argument(description: "The username of the user")] string $userId,
        IOutput $output,
    ): ExitCode {
        // ...
        return ExitCode::Success;
    }
}

Or on methods:

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;
    }

}

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI (the port of some of the files commands)

@CarlSchwan CarlSchwan self-assigned this Aug 5, 2026
@CarlSchwan
CarlSchwan requested a review from a team as a code owner August 5, 2026 14:12
@CarlSchwan CarlSchwan added 3. to review Waiting for reviews technical debt 🧱 🤔🚀 labels Aug 5, 2026
@CarlSchwan
CarlSchwan requested review from Altahrim, come-nc, leftybournes and nfebe and removed request for a team August 5, 2026 14:12
@CarlSchwan CarlSchwan changed the title Carl/ocp console Command API in OCP Aug 5, 2026
The API is inspired by modern command registration in Symfony/Console.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Make sure it is somewhat feature complete with the API used in Base.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Allow to change output depending on the verbosity set by the user.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Comment on lines 63 to +65
$format = $input->getOption('output');

if ($format === self::OUTPUT_FORMAT_PLAIN) {
if ($format === 'plain') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smell as missing const in IInput, and/or maybe a method getOutputFormat or something?

$userId = $input->getArgument('user');
public function __invoke(
IOutput $output,
#[Argument(description: 'User to refresh mounts for')] string $user,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[Argument(description: 'User to refresh mounts for')] string $user,
#[Argument(description: 'User to refresh mounts for')]
string $user,

I would prefer a line break after attribute, is that allowed by our php-cs currently?

@come-nc

come-nc commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

I think I like the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews AI assisted technical debt 🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants