From 972e0c62b38d0a77023b6771c0f8867b1c33d8c4 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Thu, 18 Feb 2016 02:42:00 +0300 Subject: [PATCH] Add global --no-warning option to occ in order not to pollute output with warnings --- console.php | 3 ++- lib/private/console/application.php | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/console.php b/console.php index d8c23d4ce00..eb6c84c3cf8 100644 --- a/console.php +++ b/console.php @@ -27,6 +27,7 @@ */ use OC\Console\Application; +use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; define('OC_CONSOLE', 1); @@ -81,7 +82,7 @@ try { } $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest()); - $application->loadCommands(new ConsoleOutput()); + $application->loadCommands(new ArgvInput(), new ConsoleOutput()); $application->run(); } catch (Exception $ex) { echo "An unhandled exception has been thrown:" . PHP_EOL; diff --git a/lib/private/console/application.php b/lib/private/console/application.php index 10ff69b1c80..0895f1788af 100644 --- a/lib/private/console/application.php +++ b/lib/private/console/application.php @@ -31,6 +31,7 @@ use OCP\IRequest; use Symfony\Component\Console\Application as SymfonyApplication; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -56,12 +57,31 @@ class Application { } /** + * @param InputInterface $input * @param OutputInterface $output * @throws \Exception */ - public function loadCommands(OutputInterface $output) { + public function loadCommands(InputInterface $input, OutputInterface $output) { // $application is required to be defined in the register_command scripts $application = $this->application; + $inputDefinition = $application->getDefinition(); + $inputDefinition->addOption( + new InputOption( + 'no-warnings', + null, + InputOption::VALUE_NONE, + 'Skip global warnings, show command output only', + null + ) + ); + try { + $input->bind($inputDefinition); + } catch (\RuntimeException $e) { + //expected if there are extra options + } + if ($input->getOption('no-warnings')) { + $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); + } require_once __DIR__ . '/../../../core/register_command.php'; if ($this->config->getSystemValue('installed', false)) { if (\OCP\Util::needUpgrade()) {