From 795eab61e45b81e62655b49855a3876ea955fd20 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 17 Jan 2023 13:26:07 +0100 Subject: [PATCH] [Console] Add inline command register example --- components/console.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/console.rst b/components/console.rst index e8f3f9a7578..63808b14df1 100644 --- a/components/console.rst +++ b/components/console.rst @@ -52,6 +52,20 @@ Then, you can register the commands using // ... $application->add(new GenerateAdminCommand()); +You can also register inline commands and define their behavior thanks to the +``Command::setCode()`` method:: + + // ... + $application->register('generate-admin') + ->addArgument('username', InputArgument::REQUIRED) + ->setCode(function (InputInterface $input, OutputInterface $output): int { + // ... + + return Command::SUCCESS; + }); + +This is useful when creating a :doc:`single-command application `. + See the :doc:`/console` article for information about how to create commands. Learn more