diff --git a/src/Composer/Command/ValidateCommand.php b/src/Composer/Command/ValidateCommand.php new file mode 100644 index 000000000..5ee8c0bd3 --- /dev/null +++ b/src/Composer/Command/ValidateCommand.php @@ -0,0 +1,56 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Command; + +use Composer\Repository\PlatformRepository; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; +use Composer\Json\JsonFile; + +/** + * @author Robert Schönthal + */ +class ValidateCommand extends Command +{ + protected function configure() + { + $this + ->setName('validate') + ->setDescription('validates a composer.json') + ->setDefinition(array( + new InputArgument('file', InputArgument::OPTIONAL, 'path to composer.json file', getcwd().'/composer.json') + )) + ->setHelp(<<php composer.phar validate for current location +or +php composer.phar validate /path/to/composer.json for custom location + +EOT + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $file = $input->getArgument('file'); + + if (!is_readable($file)) { + throw new \InvalidArgumentException('composer.json not found '.$file); + } + + $result = JsonFile::parseJson(file_get_contents($file)); + $output->writeln('valid '.$file.' is valid'); + } +} diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index c0871bf4b..bf0475e33 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -175,6 +175,7 @@ class Application extends BaseApplication $this->add(new Command\UpdateCommand()); $this->add(new Command\DebugPackagesCommand()); $this->add(new Command\SearchCommand()); + $this->add(new Command\ValidateCommand()); if ('phar:' === substr(__FILE__, 0, 5)) { $this->add(new Command\SelfUpdateCommand());