1
0
Fork 0

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

pull/1006/head
Jordi Boggiano 2012-08-15 17:42:49 +02:00
commit b5c60dd92a
1 changed files with 28 additions and 1 deletions

View File

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Factory; use Composer\Factory;
use Composer\Package\BasePackage;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Symfony\Component\Console\Input\InputInterface; 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('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', 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('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 ->setHelp(<<<EOT
The <info>init</info> command creates a basic composer.json file The <info>init</info> command creates a basic composer.json file
@ -77,7 +79,7 @@ EOT
{ {
$dialog = $this->getHelperSet()->get('dialog'); $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))); $options = array_filter(array_intersect_key($input->getOptions(), array_flip($whitelist)));
@ -90,6 +92,10 @@ EOT
$this->formatRequirements($options['require']) : $this->formatRequirements($options['require']) :
new \stdClass; new \stdClass;
if (isset($options['require-dev'])) {
$options['require-dev'] = $this->formatRequirements($options['require-dev']) ;
}
$file = new JsonFile('composer.json'); $file = new JsonFile('composer.json');
$json = $file->encode($options); $json = $file->encode($options);
@ -209,6 +215,27 @@ EOT
); );
$input->setOption('author', $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( $output->writeln(array(
'', '',
'Define your dependencies.', 'Define your dependencies.',