Permalink
Browse files

Merge remote-tracking branch 'simensen/init-min-stab'

  • Loading branch information...
2 parents dbd44d6 + d0773b2 commit b5c60dd92a7ea0e593067887a57fd282794dc76d @Seldaek Seldaek committed Aug 15, 2012
Showing with 28 additions and 1 deletion.
  1. +28 −1 src/Composer/Command/InitCommand.php
@@ -14,6 +14,7 @@
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 @@ protected function configure()
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(<<<EOT
The <info>init</info> command creates a basic composer.json file
@@ -77,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$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 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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 @@ function ($value) use ($self, $author) {
);
$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.',

0 comments on commit b5c60dd

Please sign in to comment.