1
0
Fork 0

[Config command] allow to pass options when adding a repo

pull/4815/head
Bilal Amarni 2016-01-22 11:08:00 +01:00
parent 06a21132db
commit e727f9f5fe
4 changed files with 51 additions and 3 deletions

View File

@ -466,6 +466,12 @@ changes to the repositories section by using it the following way:
php composer.phar config repositories.foo vcs https://github.com/foo/bar php composer.phar config repositories.foo vcs https://github.com/foo/bar
``` ```
If your repository requires more configuration options, you can instead pass its JSON representation :
```sh
php composer.phar config repositories.foo '{"type": "vcs", "url": "http://svn.example.org/my-project/", "trunk-path": "master"}'
```
## create-project ## create-project
You can use Composer to create new projects from an existing package. This is You can use Composer to create new projects from an existing package. This is

View File

@ -434,10 +434,19 @@ EOT
} }
if (1 === count($values)) { if (1 === count($values)) {
$bool = strtolower($values[0]); $value = strtolower($values[0]);
if (true === $booleanValidator($bool) && false === $booleanNormalizer($bool)) { if (true === $booleanValidator($value)) {
if (false === $booleanNormalizer($value)) {
return $this->configSource->addRepository($matches[1], false); return $this->configSource->addRepository($matches[1], false);
} }
} else {
$value = json_decode($values[0], true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(sprintf('%s is not valid JSON.', $values[0]));
}
return $this->configSource->addRepository($matches[1], $value);
}
} }
throw new \RuntimeException('You must pass the type and a url. Example: php composer.phar config repositories.foo vcs https://bar.com'); throw new \RuntimeException('You must pass the type and a url. Example: php composer.phar config repositories.foo vcs https://bar.com');

View File

@ -0,0 +1,15 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"repositories": {
"example_tld": {
"type": "composer",
"url": "https://example.tld",
"options": {
"ssl": {
"local_cert": "/home/composer/.ssl/composer.pem"
}
}
}
}
}

View File

@ -52,6 +52,24 @@ class JsonConfigSourceTest extends \PHPUnit_Framework_TestCase
$this->assertFileEquals($this->fixturePath('config/config-with-exampletld-repository.json'), $config); $this->assertFileEquals($this->fixturePath('config/config-with-exampletld-repository.json'), $config);
} }
public function testAddRepositoryWithOptions()
{
$config = $this->workingDir.'/composer.json';
copy($this->fixturePath('composer-repositories.json'), $config);
$jsonConfigSource = new JsonConfigSource(new JsonFile($config));
$jsonConfigSource->addRepository('example_tld', array(
'type' => 'composer',
'url' => 'https://example.tld',
'options' => array(
'ssl' => array(
'local_cert' => '/home/composer/.ssl/composer.pem'
)
)
));
$this->assertFileEquals($this->fixturePath('config/config-with-exampletld-repository-and-options.json'), $config);
}
public function testRemoveRepository() public function testRemoveRepository()
{ {
$config = $this->workingDir.'/composer.json'; $config = $this->workingDir.'/composer.json';