8000 [Console] application/command as text/xml/whatever decoupling by jfsimon · Pull Request #7454 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] application/command as text/xml/whatever decoupling #7454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
da67c12
[Console] added descriptor & refactored description commands
jfsimon Mar 22, 2013
f239b1c
[Console] added JSON descriptors
jfsimon Apr 1, 2013
bebf1eb
[Console] added markdown descriptors
jfsimon Apr 3, 2013
43b5e5c
[Console] added forgotten headers
jfsimon Apr 3, 2013
acc7414
[Console] removed unused methods (tests broken)
jfsimon Apr 3, 2013
774794c
[Console] fixed tests
jfsimon Apr 3, 2013
2066a9b
[Console] added XML descriptors
jfsimon Apr 6, 2013
47fa194
[Console] started text derciptors
jfsimon Apr 6, 2013
8b56eb1
[Console] finished text descriptors
jfsimon Apr 8, 2013
27aa872
[Console] repaired tests
jfsimon Apr 10, 2013
30d8807
[Console] re-introduced asText & asXml methods to avoid BC break
jfsimon Apr 14, 2013
9964838
[Console] added command definition merge be fore description
jfsimon Apr 14, 2013
ef6d8ba
[Console] simplified description commands
jfsimon Apr 14, 2013
389101a
[Console] re-introduced --xml option to avoid BC break
jfsimon Apr 14, 2013
84be8de
[Console] simplified mardown descriptors
jfsimon Apr 14, 2013
ce5c0fd
[Console] applied comments from github
jfsimon Apr 14, 2013
49a4612
[Console] applied comments from github
jfsimon Apr 14, 2013
20c10a5
[Console] added provider injection to descriptors
jfsimon Apr 14, 2013
9c7b358
[Console] simplified descriptors
jfsimon Apr 23, 2013
d3ec073
[Console] applied advices from github comments
jfsimon Apr 23, 2013
d70e086
[Console] removed proxy
jfsimon Apr 23, 2013
ce60fb7
[Console] simplified descriptor interface
jfsimon Apr 23, 2013
28f082e
[Console] removed changes
jfsimon Apr 23, 2013
cbb8105
[Console] moved commands arguments
jfsimon Apr 23, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Console] simplified description commands
  • Loading branch information
jfsimon committed Apr 14, 2013
commit ef6d8ba93a3b7526e28be1740fe7dc884a0fd4d0

This file was deleted.

23 changes: 9 additions & 14 deletions src/Symfony/Component/Console/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -21,7 +22,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class HelpCommand extends AbstractDescriptionCommand
class HelpCommand extends Command
{
private $command;

Expand All @@ -36,6 +37,11 @@ protected function configure()
$this
->setName('help')
->setDescription('Displays help for a command')
->setDefinition(array(
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats.'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help.'),
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
))
->setHelp(<<<EOF
The <info>%command.name%</info> command displays help for a given command:

Expand All @@ -61,17 +67,6 @@ public function setCommand(Command $command)
$this->command = $command;
}

/**
* {@inheritdoc}
*/
protected function createDefinition()
{
$definition = parent::createDefinition();
$definition->addArgument(new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'));

return $definition;
}

/**
* {@inheritdoc}
*/
Expand All @@ -81,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->command = $this->getApplication()->find($input->getArgument('command_name'));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--xml is still supported, so we must convert it to the right format too.

parent::execute($input, $output);
$this->getHelper('descriptor')->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw'));
$helper = new DescriptorHelper();
$helper->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw'));
$this->command = null;
}
}
19 changes: 11 additions & 8 deletions src/Symfony/Component/Console/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -21,7 +23,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ListCommand extends AbstractDescriptionCommand
class ListCommand extends Command
{
/**
* {@inheritdoc}
Expand All @@ -33,6 +35,7 @@ protected function configure()
$this
->setName('list')
->setDescription('Lists commands')
->setDefinition($this->createDefinition())
->setHelp(<<<EOF
The <info>%command.name%</info> command lists all commands:

Expand All @@ -59,10 +62,11 @@ protected function configure()
*/
protected function createDefinition()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why changing it from private to protected ?

{
$definition = parent::createDefinition();
$definition->addArgument(new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'));

return $definition;
return new InputDefinition(array(
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats.'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list.'),
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
));
}

/**
Expand All @@ -78,8 +82,7 @@ protected function getNativeDefinition()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);

$this->getHelper('descriptor')->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw'));
$helper = new DescriptorHelper();
$helper->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw'));
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Helper/DescriptorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class DescriptorHelper extends Helper
*
* @param DescriptorProvider $provider
*/
public function __construct(DescriptorP 9E88 rovider $provider)
public function __construct(DescriptorProvider $provider = null)
{
$this->provider = $provider;
$this->provider = $provider ?: new DescriptorProvider();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]}
{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help.","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Tests/Fixtures/application_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ To display the list of available commands, please use the <info>list</info> comm
* Accept value: no
* Is value required: no
* Is multiple: no
* Description: To output raw command list.
* Description: To output raw command help.
* Default: `false`

**help:**
Expand Down Expand Up @@ -165,7 +165,7 @@ It's also possible to get raw list of commands (useful for embedding command run
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: To output help in other formats.
* Description: To output list in other formats.
* Default: `NULL`

**raw:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list.</description>
<description>To output raw command help.</description>
</option>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
Expand Down Expand Up @@ -80,7 +80,7 @@
</arguments>
<options>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats.</description>
<description>To output list in other formats.</description>
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
Expand Down
Loading
0