@@ -8,44 +8,44 @@ When building a command line tool, you may not need to provide several commands.
8
8
In such case, having to pass the command name each time is tedious. Fortunately,
9
9
it is possible to remove this need by declaring a single command application::
10
10
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();
31
31
32
32
The method :method: `Symfony\\ Component\\ Console\\ Application::setDefaultCommand `
33
33
accepts a boolean as second parameter. If true, the command ``echo `` will then
34
34
always be used, without having to pass its name.
35
35
36
36
Of course, you can still register a command as usual::
37
37
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';
41
41
42
- use Acme\Command\DefaultCommand;
43
- use Symfony\Component\Console\Application;
42
+ use Acme\Command\DefaultCommand;
43
+ use Symfony\Component\Console\Application;
44
44
45
- $application = new Application('echo', '1.0.0');
46
- $command = new DefaultCommand();
45
+ $application = new Application('echo', '1.0.0');
46
+ $command = new DefaultCommand();
47
47
48
- $application->add($command);
48
+ $application->add($command);
49
49
50
- $application->setDefaultCommand($command->getName(), true);
51
- $application->run();
50
+ $application->setDefaultCommand($command->getName(), true);
51
+ $application->run();
0 commit comments