From 7be31e12ecdf45df8c0e115c0a14928d699590ef Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Mon, 1 Oct 2012 11:07:53 -0500 Subject: [PATCH] add a repository in either the global config or the local composer.json file --- .../Command/ConfigRepositoriesAddCommand.php | 101 ++++++++++++++++++ src/Composer/Console/Application.php | 2 +- 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/Composer/Command/ConfigRepositoriesAddCommand.php diff --git a/src/Composer/Command/ConfigRepositoriesAddCommand.php b/src/Composer/Command/ConfigRepositoriesAddCommand.php new file mode 100644 index 000000000..26cf198ee --- /dev/null +++ b/src/Composer/Command/ConfigRepositoriesAddCommand.php @@ -0,0 +1,101 @@ + + * 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 Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Composer\Factory; +use Composer\Installer; +use Composer\Json\JsonFile; +use Composer\Json\JsonManipulator; + +class ConfigRepositoriesAddCommand extends Command +{ + protected $repositories = array(); + + protected function configure() + { + $this + ->setName('config:repositories:add') + ->setDescription('Add a repository') + ->setDefinition(array( + new InputOption('global', null, InputOption::VALUE_NONE, 'Set this as a global config settings.') + )) + ->setHelp(<<get('home') . '/config.json'); + if (!$globalConfig->exists()) { + touch($globalConfig->getPath()); + $globalConfig->write(array()); + } + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $configFile = $input->getOption('global') + ? (Factory::createConfig()->get('home') . '/config.json') + : 'composer.json'; + + $configFile = new JsonFile($configFile); + + if (count($this->repositories)) { + $config = $configFile->read(); + foreach ($this->repositories as $repo) { + $config['repositories'][] = array( + 'type' => $repo['type'], + 'url' => $repo['url'], + ); + } + $configFile->write($config); + } + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $dialog = $this->getHelperSet()->get('dialog'); + + /** + * @todo Update this with more info + */ + $output->writeln(array( + '', + 'Add a repository', + '', + )); + + /** + * @todo put this into a loop so user can add many repositories at + * the same time. + */ + $type = $dialog->ask($output, $dialog->getQuestion('Repository Type')); + $repo = $dialog->ask($output, $dialog->getQuestion('Repository URL')); + if (null !== $type && null !== $repo) { + $this->repositories[] = array( + 'type' => $type, + 'url' => $repo, + ); + } + } +} + diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 856ea5583..aee57a865 100755 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -155,7 +155,7 @@ class Application extends BaseApplication { $commands = parent::getDefaultCommands(); $commands[] = new Command\AboutCommand(); - $commands[] = new Command\ConfigCommand(); + $commands[] = new Command\ConfigRepositoriesAddCommand(); $commands[] = new Command\DependsCommand(); $commands[] = new Command\InitCommand(); $commands[] = new Command\InstallCommand();