From d62a1ad1c1e8ddc4ae30129ed13b310559b6173f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 12 Dec 2011 22:14:01 +0100 Subject: [PATCH] Adjustments to the validate command --- src/Composer/Command/ValidateCommand.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) 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'); } }