1
0
Fork 0

Adjustments to the validate command

pull/156/merge
Jordi Boggiano 2011-12-12 22:14:01 +01:00
parent a193ec9942
commit d62a1ad1c1
1 changed files with 16 additions and 7 deletions

View File

@ -20,6 +20,7 @@ use Composer\Json\JsonFile;
/** /**
* @author Robert Schönthal <seroscho@googlemail.com> * @author Robert Schönthal <seroscho@googlemail.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
class ValidateCommand extends Command class ValidateCommand extends Command
{ {
@ -29,13 +30,10 @@ class ValidateCommand extends Command
->setName('validate') ->setName('validate')
->setDescription('validates a composer.json') ->setDescription('validates a composer.json')
->setDefinition(array( ->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(<<<EOT ->setHelp(<<<EOT
The validate command validates a given composer.json The validate command validates a given composer.json
<info>php composer.phar validate</info> for current location
or
<info>php composer.phar validate /path/to/composer.json</info> for custom location
EOT EOT
) )
@ -46,11 +44,22 @@ EOT
{ {
$file = $input->getArgument('file'); $file = $input->getArgument('file');
if (!file_exists($file)) {
$output->writeln('<error>'.$file.' not found.</error>');
return;
}
if (!is_readable($file)) { if (!is_readable($file)) {
throw new \InvalidArgumentException('composer.json not found '.$file); $output->writeln('<error>'.$file.' is not readable.</error>');
return;
} }
$result = JsonFile::parseJson(file_get_contents($file)); try {
$output->writeln('<info>valid</info> '.$file.' is valid'); JsonFile::parseJson(file_get_contents($file));
} catch (\Exception $e) {
$output->writeln('<error>'.$e->getMessage().'</error>');
return;
}
$output->writeln('<info>'.$file.' is valid</info>');
} }
} }