Skip to content

How to create a command inline (without creating a Command class) #16214

@GromNaN

Description

@GromNaN

For people looking for a micro-framework for cli, the Console component provides a fluent interface to declare commands. I don't find it in the doc.

Example:

$app->register('hello')
    ->addArgument('name', InputArgument::OPTIONAL, '', 'World!')
    ->setCode(function (InputInterface $input, OutputInterface $output): int {
        $output->writeln('Hello, ' . $input->getArgument('name'));
        
        return Command::SUCCESS;
    });

This should be pointed in this section of the doc. Maybe with a dedicated page.
https://symfony.com/doc/current/components/console.html#creating-a-console-application

Existing frameworks are good at presenting this feature, but are almost unmaintained (Silly, Cylex).

(Triggered by brefphp/bref#1117)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConsolehasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions