2017-07-07 07:17:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\RecipePlugin;
|
|
|
|
|
|
|
|
use Composer\Command\BaseCommand;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
2017-07-10 02:10:18 +02:00
|
|
|
/**
|
|
|
|
* Provides the 'require-recipe' command which allows a new recipe to be installed, but also
|
|
|
|
* soft-updates any existing recipe.
|
|
|
|
*/
|
2017-07-07 07:17:12 +02:00
|
|
|
class RequireRecipeCommand extends BaseCommand
|
|
|
|
{
|
2017-07-10 02:10:18 +02:00
|
|
|
use RecipeCommandBehaviour;
|
|
|
|
|
2017-07-07 07:17:12 +02:00
|
|
|
public function configure()
|
|
|
|
{
|
|
|
|
$this->setName('require-recipe');
|
|
|
|
$this->setDescription('Invoke this command to inline a recipe into your root composer.json');
|
|
|
|
$this->addArgument(
|
|
|
|
'recipe',
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
'Recipe name to require inline'
|
|
|
|
);
|
|
|
|
$this->addArgument(
|
|
|
|
'version',
|
2017-07-10 00:47:36 +02:00
|
|
|
InputArgument::OPTIONAL,
|
|
|
|
'Version or constraint to require'
|
2017-07-07 07:17:12 +02:00
|
|
|
);
|
|
|
|
$this->addUsage('silverstripe/recipe-blogging 1.0.0');
|
|
|
|
$this->setHelp(
|
|
|
|
<<<HELP
|
|
|
|
Running this command will inline any given recipe into your composer.json, allowing you to
|
|
|
|
modify it as though these dependencies were natively part of your own.
|
|
|
|
|
|
|
|
Running command <info>composer require-recipe silverstripe/recipe-blogging 1.0.0</info> adds the following:
|
|
|
|
|
|
|
|
<comment>
|
|
|
|
"require": {
|
|
|
|
"silverstripe/blog": "3.0.0",
|
|
|
|
"silverstripe/lumberjack": "3.0.1",
|
|
|
|
"silverstripe/comments": "2.1.0"
|
|
|
|
},
|
|
|
|
"provide": {
|
|
|
|
"silverstripe/recipe-blogging": "1.0.0"
|
|
|
|
}
|
|
|
|
</comment>
|
|
|
|
HELP
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$recipe = $input->getArgument('recipe');
|
2017-07-10 00:47:36 +02:00
|
|
|
$constraint = $input->getArgument('version');
|
2017-07-07 07:17:12 +02:00
|
|
|
|
2017-07-10 02:10:18 +02:00
|
|
|
// Check if this is already installed and notify users
|
2017-07-10 00:47:36 +02:00
|
|
|
$installedVersion = $this->findInstalledVersion($recipe);
|
2017-07-07 07:17:12 +02:00
|
|
|
|
2017-07-10 02:22:15 +02:00
|
|
|
// Install recipe
|
|
|
|
return $this->installRecipe($output, $recipe, $constraint, $installedVersion);
|
2017-07-07 07:17:12 +02:00
|
|
|
}
|
|
|
|
}
|