Skip to content

Commit c7463b2

Browse files
committed
minor #17759 [Console] Add inline command register example (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Console] Add inline command register example Fixes #16214 I was brief on the example. Since there is already an example of using `setCode` in the doc, I think it was only necessary to mention the possibility to do that in the main page of the Console component, before referring to the single-line command page with more details. Commits ------- 795eab6 [Console] Add inline command register example
2 parents 5b2958a + 795eab6 commit c7463b2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/console.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ Then, you can register the commands using
5252
// ...
5353
$application->add(new GenerateAdminCommand());
5454

55+
You can also register inline commands and define their behavior thanks to the
56+
``Command::setCode()`` method::
57+
58+
// ...
59+
$application->register('generate-admin')
60+
->addArgument('username', InputArgument::REQUIRED)
61+
->setCode(function (InputInterface $input, OutputInterface $output): int {
62+
// ...
63+
64+
return Command::SUCCESS;
65+
});
66+
67+
This is useful when creating a :doc:`single-command application </components/console/single_command_tool>`.
68+
5569
See the :doc:`/console` article for information about how to create commands.
5670

5771
Learn more

0 commit comments

Comments
 (0)