Created
October 24, 2012 21:54
-
-
Save MattKetmo/3949165 to your computer and use it in GitHub Desktop.
Option --quiet in Symfony2 command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\NullOutput; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class NullOutputCommand extends Command | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function configure() | |
{ | |
$this | |
->setName('dummy') | |
->addOption('quiet', 'q', InputOption::VALUE_NONE, 'Disable all output of the program.') | |
; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
if (true === $input->getOption('quiet')) { | |
$output = new NullOutput(); | |
} | |
// ... | |
$output->writeln('This line won\'t be printed with --quiet option'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment