Skip to content

Instantly share code, notes, and snippets.

@MattKetmo
Created October 24, 2012 21:54
Show Gist options
  • Save MattKetmo/3949165 to your computer and use it in GitHub Desktop.
Save MattKetmo/3949165 to your computer and use it in GitHub Desktop.
Option --quiet in Symfony2 command
<?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