Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (34 sloc) 1.537 kB
7f8ebd5 @lsmith77 fixed README for Console
lsmith77 authored
1 Console Component
2 =================
3
456d1b8 @fabpot tweaked the README files
fabpot authored
4 Console eases the creation of beautiful and testable command line interfaces.
5
6 The Application object manages the CLI application:
7
8 use Symfony\Component\Console\Application;
9
10 $console = new Application();
11 $console->run();
12
13 The ``run()`` method parses the arguments and options passed on the command
14 line and executes the right command.
15
16 Registering a new command can easily be done via the ``register()`` method,
17 which returns a ``Command`` instance:
18
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Input\InputArgument;
21 use Symfony\Component\Console\Input\InputOption;
22 use Symfony\Component\Console\Output\OutputInterface;
23
24 $console
25 ->register('ls')
26 ->setDefinition(array(
27 new InputArgument('dir', InputArgument::REQUIRED, 'Directory name'),
28 ))
29 ->setDescription('Displays the files in the given directory')
30 ->setCode(function (InputInterface $input, OutputInterface $output) {
31 $dir = $input->getArgument('dir');
32
33 $output->writeln(sprintf('Dir listing for <info>%s</info>', $dir));
34 })
35 ;
36
37 You can also register new commands via classes.
38
39 The component provides a lot of features like output coloring, input and
40 output abstractions (so that you can easily unit-test your commands),
41 validation, automatic help messages, ...
7f8ebd5 @lsmith77 fixed README for Console
lsmith77 authored
42
43 Resources
44 ---------
45
81b0979 @fabpot moved component and bridge unit tests to the src/ directory
fabpot authored
46 You can run the unit tests with the following command:
7f8ebd5 @lsmith77 fixed README for Console
lsmith77 authored
47
81b0979 @fabpot moved component and bridge unit tests to the src/ directory
fabpot authored
48 phpunit -c src/Symfony/Component/Console/
Something went wrong with that request. Please try again.