From 05e196893b1225898de280ef8f97d5f2be684e8f Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sat, 28 Feb 2015 12:59:43 -0800 Subject: [PATCH] Add --no-check-publish option to "composer validate" This is useful when you want to use composer to manage dependencies, but don't actually want your project to be installable as a composer package. Any issues that would prevent publishing are still shown, but as a warning instead of an error. --- src/Composer/Command/ValidateCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 08aaef209..9298e4175 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -37,6 +37,7 @@ class ValidateCommand extends Command ->setDescription('Validates a composer.json') ->setDefinition(array( new InputOption('no-check-all', null, InputOption::VALUE_NONE, 'Do not make a complete validation'), + new InputOption('no-check-publish', null, InputOption::VALUE_NONE, 'Do not check for publish errors'), new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file', './composer.json') )) ->setHelp(<<getIO()); $checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL; + $checkPublish = !$input->getOption('no-check-publish'); list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll); // output errors/warnings @@ -86,16 +88,23 @@ EOT } $messages = array( - 'error' => array_merge($errors, $publishErrors), + 'error' => $errors, 'warning' => $warnings, ); + // If checking publish errors, display them errors, otherwise just show them as warnings + if ($checkPublish) { + $messages['error'] = array_merge($messages['error'], $publishErrors); + } else { + $messages['warning'] = array_merge($messages['warning'], $publishErrors); + } + foreach ($messages as $style => $msgs) { foreach ($msgs as $msg) { $this->getIO()->writeError('<' . $style . '>' . $msg . ''); } } - return $errors || $publishErrors ? 1 : 0; + return $errors || ($publishErrors && $checkPublish) ? 1 : 0; } }