From d0773b20dfb6c0ce286aec6d597385e23d6cc7ba Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Tue, 14 Aug 2012 12:03:38 -0700 Subject: [PATCH] Added minimum-stability option to init command, minor bug fixes Added the ability to specify `minimum-stability` as an option. Also added `homepage` and `require-dev` to the whitelist and added necessary code to format dev requirements only if dev requirements are present. --- src/Composer/Command/InitCommand.php | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 1a4ac9948..b9bce4705 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -14,6 +14,7 @@ namespace Composer\Command; use Composer\Json\JsonFile; use Composer\Factory; +use Composer\Package\BasePackage; use Composer\Repository\CompositeRepository; use Composer\Repository\PlatformRepository; use Symfony\Component\Console\Input\InputInterface; @@ -61,6 +62,7 @@ class InitCommand extends Command new InputOption('homepage', null, InputOption::VALUE_NONE, 'Homepage of package'), new InputOption('require', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Package to require with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"'), new InputOption('require-dev', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Package to require for development with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"'), + new InputOption('minimum-stability', null, InputOption::VALUE_NONE, 'Minimum stability (empty or one of: '.implode(', ', array_keys(BasePackage::$stabilities)).')'), )) ->setHelp(<<init command creates a basic composer.json file @@ -77,7 +79,7 @@ EOT { $dialog = $this->getHelperSet()->get('dialog'); - $whitelist = array('name', 'description', 'author', 'require'); + $whitelist = array('name', 'description', 'author', 'homepage', 'require', 'require-dev', 'minimum-stability'); $options = array_filter(array_intersect_key($input->getOptions(), array_flip($whitelist))); @@ -90,6 +92,10 @@ EOT $this->formatRequirements($options['require']) : new \stdClass; + if (isset($options['require-dev'])) { + $options['require-dev'] = $this->formatRequirements($options['require-dev']) ; + } + $file = new JsonFile('composer.json'); $json = $file->encode($options); @@ -209,6 +215,27 @@ EOT ); $input->setOption('author', $author); + $minimumStability = $input->getOption('minimum-stability') ?: ''; + $minimumStability = $dialog->askAndValidate( + $output, + $dialog->getQuestion('Minimum Stability', $minimumStability), + function ($value) use ($self, $minimumStability) { + if (null === $value) { + return $minimumStability; + } + + if (!isset(BasePackage::$stabilities[$value])) { + throw new \InvalidArgumentException( + 'Invalid minimum stability "'.$value.'". Must be empty or one of: '. + implode(', ', array_keys(BasePackage::$stabilities)) + ); + } + + return $value; + } + ); + $input->setOption('minimum-stability', $minimumStability); + $output->writeln(array( '', 'Define your dependencies.',