@@ -8,44 +8,44 @@ When building a command line tool, you may not need to provide several commands.
88In such case, having to pass the command name each time is tedious. Fortunately,
99it is possible to remove this need by declaring a single command application::
1010
11- #!/usr/bin/env php
12- <?php
13- require __DIR__.'/vendor/autoload.php';
14-
15- use Symfony\Component\Console\Application;
16- use Symfony\Component\Console\Input\InputArgument;
17- use Symfony\Component\Console\Input\InputInterface;
18- use Symfony\Component\Console\Input\InputOption;
19- use Symfony\Component\Console\Output\OutputInterface;
20-
21- (new Application('echo', '1.0.0'))
22- ->register('echo')
23- ->addArgument('foo', InputArgument::OPTIONAL, 'The directory')
24- ->addOption('bar', null, InputOption::VALUE_REQUIRED)
25- ->setCode(function(InputInterface $input, OutputInterface $output) {
26- // output arguments and options
27- })
28- ->getApplication()
29- ->setDefaultCommand('echo', true) // Single command application
30- ->run();
11+ #!/usr/bin/env php
12+ <?php
13+ require __DIR__.'/vendor/autoload.php';
14+
15+ use Symfony\Component\Console\Application;
16+ use Symfony\Component\Console\Input\InputArgument;
17+ use Symfony\Component\Console\Input\InputInterface;
18+ use Symfony\Component\Console\Input\InputOption;
19+ use Symfony\Component\Console\Output\OutputInterface;
20+
21+ (new Application('echo', '1.0.0'))
22+ ->register('echo')
23+ ->addArgument('foo', InputArgument::OPTIONAL, 'The directory')
24+ ->addOption('bar', null, InputOption::VALUE_REQUIRED)
25+ ->setCode(function(InputInterface $input, OutputInterface $output) {
26+ // output arguments and options
27+ })
28+ ->getApplication()
29+ ->setDefaultCommand('echo', true) // Single command application
30+ ->run();
3131
3232The method :method: `Symfony\\ Component\\ Console\\ Application::setDefaultCommand `
3333accepts a boolean as second parameter. If true, the command ``echo `` will then
3434always be used, without having to pass its name.
3535
3636You can still register a command as usual::
3737
38- #!/usr/bin/env php
39- <?php
40- require __DIR__.'/vendor/autoload.php';
38+ #!/usr/bin/env php
39+ <?php
40+ require __DIR__.'/vendor/autoload.php';
4141
42- use Acme\Command\DefaultCommand;
43- use Symfony\Component\Console\Application;
42+ use Acme\Command\DefaultCommand;
43+ use Symfony\Component\Console\Application;
4444
45- $application = new Application('echo', '1.0.0');
46- $command = new DefaultCommand();
45+ $application = new Application('echo', '1.0.0');
46+ $command = new DefaultCommand();
4747
48- $application->add($command);
48+ $application->add($command);
4949
50- $application->setDefaultCommand($command->getName(), true);
51- $application->run();
50+ $application->setDefaultCommand($command->getName(), true);
51+ $application->run();
0 commit comments