ArchiveCommand improvements
parent
400f35efde
commit
4f5d979bee
|
@ -18,6 +18,9 @@ use Composer\DependencyResolver\Pool;
|
||||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
use Composer\Repository\CompositeRepository;
|
use Composer\Repository\CompositeRepository;
|
||||||
use Composer\Script\ScriptEvents;
|
use Composer\Script\ScriptEvents;
|
||||||
|
use Composer\Plugin\CommandEvent;
|
||||||
|
use Composer\Plugin\PluginEvents;
|
||||||
|
use Composer\Package\Version\VersionParser;
|
||||||
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
@ -38,7 +41,7 @@ class ArchiveCommand extends Command
|
||||||
->setDescription('Create an archive of this composer package')
|
->setDescription('Create an archive of this composer package')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('package', InputArgument::OPTIONAL, 'The package to archive instead of the current project'),
|
new InputArgument('package', InputArgument::OPTIONAL, 'The package to archive instead of the current project'),
|
||||||
new InputArgument('version', InputArgument::OPTIONAL, 'The package version to archive'),
|
new InputArgument('version', InputArgument::OPTIONAL, 'A version constraint to find the package to archive'),
|
||||||
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar or zip', 'tar'),
|
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar or zip', 'tar'),
|
||||||
new InputOption('dir', false, InputOption::VALUE_REQUIRED, 'Write the archive to this directory', '.'),
|
new InputOption('dir', false, InputOption::VALUE_REQUIRED, 'Write the archive to this directory', '.'),
|
||||||
))
|
))
|
||||||
|
@ -56,7 +59,12 @@ EOT
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$this->getComposer()->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_ARCHIVE_CMD);
|
$composer = $this->getComposer(false);
|
||||||
|
if ($composer) {
|
||||||
|
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'archive', $input, $output);
|
||||||
|
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
|
||||||
|
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_ARCHIVE_CMD);
|
||||||
|
}
|
||||||
|
|
||||||
$returnCode = $this->archive(
|
$returnCode = $this->archive(
|
||||||
$this->getIO(),
|
$this->getIO(),
|
||||||
|
@ -66,8 +74,8 @@ EOT
|
||||||
$input->getOption('dir')
|
$input->getOption('dir')
|
||||||
);
|
);
|
||||||
|
|
||||||
if (0 === $returnCode) {
|
if (0 === $returnCode && $composer) {
|
||||||
$this->getComposer()->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ARCHIVE_CMD);
|
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ARCHIVE_CMD);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $returnCode;
|
return $returnCode;
|
||||||
|
@ -112,16 +120,17 @@ EOT
|
||||||
$pool = new Pool();
|
$pool = new Pool();
|
||||||
$pool->addRepository($repos);
|
$pool->addRepository($repos);
|
||||||
|
|
||||||
$constraint = ($version) ? new VersionConstraint('>=', $version) : null;
|
$parser = new VersionParser();
|
||||||
$packages = $pool->whatProvides($packageName, $constraint);
|
$constraint = ($version) ? $parser->parseConstraints($version) : null;
|
||||||
|
$packages = $pool->whatProvides($packageName, $constraint, true);
|
||||||
|
|
||||||
if (count($packages) > 1) {
|
if (count($packages) > 1) {
|
||||||
$package = $packages[0];
|
$package = reset($packages);
|
||||||
$io->write('<info>Found multiple matches, selected '.$package->getPrettyString().'.</info>');
|
$io->write('<info>Found multiple matches, selected '.$package->getPrettyString().'.</info>');
|
||||||
$io->write('Alternatives were '.implode(', ', array_map(function ($p) { return $p->getPrettyString(); }, $packages)).'.');
|
$io->write('Alternatives were '.implode(', ', array_map(function ($p) { return $p->getPrettyString(); }, $packages)).'.');
|
||||||
$io->write('<comment>Please use a more specific constraint to pick a different package.</comment>');
|
$io->write('<comment>Please use a more specific constraint to pick a different package.</comment>');
|
||||||
} elseif ($packages) {
|
} elseif ($packages) {
|
||||||
$package = $packages[0];
|
$package = reset($packages);
|
||||||
$io->write('<info>Found an exact match '.$package->getPrettyString().'.</info>');
|
$io->write('<info>Found an exact match '.$package->getPrettyString().'.</info>');
|
||||||
} else {
|
} else {
|
||||||
$io->write('<error>Could not find a package matching '.$packageName.'.</error>');
|
$io->write('<error>Could not find a package matching '.$packageName.'.</error>');
|
||||||
|
|
Loading…
Reference in New Issue