diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php index 5ee8c0bd3..18a854e4a 100644 --- a/src/Composer/Command/ValidateCommand.php +++ b/src/Composer/Command/ValidateCommand.php @@ -20,6 +20,7 @@ use Composer\Json\JsonFile; /** * @author Robert Schönthal + * @author Jordi Boggiano */ class ValidateCommand extends Command { @@ -29,13 +30,10 @@ class ValidateCommand extends Command ->setName('validate') ->setDescription('validates a composer.json') ->setDefinition(array( - new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file', getcwd().'/composer.json') + new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file', './composer.json') )) ->setHelp(<<php composer.phar validate for current location -or -php composer.phar validate /path/to/composer.json for custom location EOT ) @@ -46,11 +44,22 @@ EOT { $file = $input->getArgument('file'); + if (!file_exists($file)) { + $output->writeln(''.$file.' not found.'); + return; + } if (!is_readable($file)) { - throw new \InvalidArgumentException('composer.json not found '.$file); + $output->writeln(''.$file.' is not readable.'); + return; } - $result = JsonFile::parseJson(file_get_contents($file)); - $output->writeln('valid '.$file.' is valid'); + try { + JsonFile::parseJson(file_get_contents($file)); + } catch (\Exception $e) { + $output->writeln(''.$e->getMessage().''); + return; + } + + $output->writeln(''.$file.' is valid'); } }