Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 795eab6

Browse filesBrowse files
[Console] Add inline command register example
1 parent 52c38a8 commit 795eab6
Copy full SHA for 795eab6

File tree

Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed

‎components/console.rst

Copy file name to clipboardExpand all lines: components/console.rst
+14Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.