Skip to content

Commit 2d21a17

Browse files
committed
Remove all other duplication from components article
1 parent cd142c7 commit 2d21a17

File tree

1 file changed

+14
-77
lines changed

1 file changed

+14
-77
lines changed

components/console.rst

+14-77
Original file line numberDiff line numberDiff line change
@@ -22,95 +22,31 @@ You can install the component in 2 different ways:
2222

2323
.. include:: /components/require_autoload.rst.inc
2424

25-
Creating a basic Command
26-
------------------------
27-
28-
To make a console command that greets you from the command line, create ``GreetCommand.php``
29-
and add the following to it::
30-
31-
namespace Acme\Console\Command;
32-
33-
use Symfony\Component\Console\Command\Command;
34-
use Symfony\Component\Console\Input\InputArgument;
35-
use Symfony\Component\Console\Input\InputInterface;
36-
use Symfony\Component\Console\Input\InputOption;
37-
use Symfony\Component\Console\Output\OutputInterface;
38-
39-
class GreetCommand extends Command
40-
{
41-
protected function configure()
42-
{
43-
$this
44-
->setName('demo:greet')
45-
->setDescription('Greet someone')
46-
->addArgument(
47-
'name',
48-
InputArgument::OPTIONAL,
49-
'Who do you want to greet?'
50-
)
51-
->addOption(
52-
'yell',
53-
null,
54-
InputOption::VALUE_NONE,
55-
'If set, the task will yell in uppercase letters'
56-
)
57-
;
58-
}
59-
60-
protected function execute(InputInterface $input, OutputInterface $output)
61-
{
62-
$name = $input->getArgument('name');
63-
if ($name) {
64-
$text = 'Hello '.$name;
65-
} else {
66-
$text = 'Hello';
67-
}
68-
69-
if ($input->getOption('yell')) {
70-
$text = strtoupper($text);
71-
}
72-
73-
$output->writeln($text);
74-
}
75-
}
76-
77-
You also need to create the file to run at the command line which creates
78-
an ``Application`` and adds commands to it::
25+
Creating an Application File
26+
----------------------------
27+
28+
At first, you need to create a file to run commands from the console::
7929

8030
#!/usr/bin/env php
8131
<?php
8232
// application.php
8333

8434
require __DIR__.'/vendor/autoload.php';
8535

86-
use Acme\Console\Command\GreetCommand;
8736
use Symfony\Component\Console\Application;
8837

8938
$application = new Application();
90-
$application->add(new GreetCommand());
91-
$application->run();
92-
93-
Test the new console command by running the following
94-
95-
.. code-block:: bash
96-
97-
$ php application.php demo:greet Fabien
9839

99-
This will print the following to the command line:
40+
// ... register commands
10041

101-
.. code-block:: text
102-
103-
Hello Fabien
104-
105-
You can also use the ``--yell`` option to make everything uppercase:
106-
107-
.. code-block:: bash
108-
109-
$ php application.php demo:greet Fabien --yell
42+
$application->run();
11043

111-
This prints::
44+
See the :doc:`/console` article for information about how to create commands.
45+
You can register the commands using
46+
:method:`Symfony\\Component\\Console\\Application::add`::
11247

113-
HELLO FABIEN
48+
// ...
49+
$application->add(new GenerateAdminCommand());
11450

11551
Learn More
11652
----------
@@ -119,7 +55,8 @@ Learn More
11955
:maxdepth: 1
12056
:glob:
12157

122-
console/*
123-
console/helpers/index
58+
/console
59+
/components/console/*
60+
/components/console/helpers/index
12461

12562
.. _Packagist: https://packagist.org/packages/symfony/console

0 commit comments

Comments
 (0)