Closed
Description
Hi,
(first attempt at contributing to symfony here)
I was reading on creating single command applications with Symfony console (because that's what I mostly need) and that felt a bit cumbersome/too much boilerplate.
Would there be interest in including something like the helper class below in the Symfony\Component\Console
namespace, to make creating single command applications easier?
class SingleCommandApplication extends Application
{
private $singleCommandName;
public function __construct(Command $command, $name = 'UNKNOWN', $version = 'UNKNOWN')
{
parent::__construct($name, $version);
// Add the given command as single (publicly accessible) command.
$this->add($command);
$this->singleCommandName = $command->getName();
// Override the Application's definition so that it does not
// require a command name as first argument.
$this->getDefinition()->setArguments();
}
protected function getCommandName(InputInterface $input)
{
return $this->singleCommandName;
}
}
Usage example (based on http://symfony.com/doc/current/components/console/introduction.html):
$application = new SingleCommandApplication(new GreetCommand());
$application->run();
I omitted docblocks and such to keep it to the point.
I just wanted to collect some quick feedback on this idea before making this a real pull request.
thanks.