mnapoli / silly

Silly CLI micro-framework based on Symfony Console
MIT License
922 stars 52 forks source link

Question: injecting Symfony\Component\Console\Style\SymfonyStyle ? #36

Closed gou1 closed 7 years ago

gou1 commented 7 years ago

Hello there!

Silly is great for quick and clean CLI apps ! So is SymfonyStyle (http://symfony.com/blog/new-in-symfony-2-8-console-style-guide) for quickly handling i/o. Right now, using it is a bit verbose:

$app->command('meh', function(InputInterface $input, OutputInterface $output){
    $io = new SymfonyStyle($input, $output);
    $io->comment('Aye aye, sir');
});

In an ideal world, i'd like to be able to:

$app->command('yeah', function (SymfonyStyle $io) {
    $io->comment('Aye aye, sir');
});

I tried to use DI for this, but it seems I cannot inject Request/Response in my service. Something like:

$pimple[SymfonyStyle::class] = function ($pimple) {
    return new SymfonyStyle($pimple['input'], $pimple['output']);
};

or like:

$pimple[SymfonyStyle::class] = function (InputInterface $input, OutputInterface $output) {
    return new SymfonyStyle($input, $output);
};

Eventually:

Thanks a lot!

mnapoli commented 7 years ago

Hi @gou1, that's a great idea! I've opened #38 to add that.

gou1 commented 7 years ago

You rock dude 💯