From 680082c5fe54bf1afd40af3af7f312d1cea267fe Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Tue, 23 Jun 2015 22:03:35 +0200 Subject: [PATCH] output based purely on verbosity --- src/Composer/Command/SuggestsCommand.php | 34 ++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Composer/Command/SuggestsCommand.php b/src/Composer/Command/SuggestsCommand.php index 73e988beb..13558b693 100644 --- a/src/Composer/Command/SuggestsCommand.php +++ b/src/Composer/Command/SuggestsCommand.php @@ -15,9 +15,7 @@ namespace Composer\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Finder\Exception\AccessDeniedException; class SuggestsCommand extends Command { @@ -47,11 +45,7 @@ EOT throw new \RuntimeException('Lockfile seems to be empty?'); } - $stderr = $output; - if ($output instanceof ConsoleOutputInterface) { - $stderr = $output->getErrorOutput(); - } - + $io = $this->getIO(); $list = $lock['packages']; if (!$input->getOption('no-dev')) { @@ -62,14 +56,26 @@ EOT foreach ($list as $package) { if (!empty($package['suggest']) && (empty($packages) || in_array($package['name'], $packages))) { - $stderr->writeln(sprintf('%s suggests:', $package['name'])); - foreach ($package['suggest'] as $target => $reason) { - if (empty($reason)) { - $reason = '*'; - } + $this->printSuggestions($package['name'], $package['suggest']); + } + } + } + + protected function printSuggestions($name, $suggests) + { + $io = $this->getIO(); + + foreach ($suggests as $target => $reason) { + if (empty($reason)) { + $reason = '*'; + } - $output->writeln(sprintf('%s: %s', $target, $reason)); - } + if ($io->isVeryVerbose()) { + $io->write(sprintf('%s suggests %s: %s', $name, $target, $reason)); + } elseif ($io->isVerbose()) { + $io->write(sprintf('%s suggests %s', $name, $target)); + } else { + $io->write(sprintf('%s', $target)); } } }