diff --git a/src/Composer/Command/ArchiveCommand.php b/src/Composer/Command/ArchiveCommand.php index c305ce8da..9a97289f8 100644 --- a/src/Composer/Command/ArchiveCommand.php +++ b/src/Composer/Command/ArchiveCommand.php @@ -36,7 +36,7 @@ class ArchiveCommand extends Command ->setName('archive') ->setDescription('Create an archive of this composer package') ->setDefinition(array( - new InputArgument('package', InputArgument::REQUIRED, 'The package to archive'), + 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 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', '.'), @@ -44,9 +44,9 @@ class ArchiveCommand extends Command ->setHelp(<<archive command creates an archive of the specified format containing the files and directories of the Composer project or the specified -package and writes it to the specified directory. +package in the specified version and writes it to the specified directory. -php composer.phar archive [--format=zip] [--dir=/foo] package version +php composer.phar archive [--format=zip] [--dir=/foo] [package] [version] EOT ) @@ -64,16 +64,20 @@ EOT ); } - public function archive(IOInterface $io, $packageName, $version = false, $format = 'tar', $dest = '.') + public function archive(IOInterface $io, $packageName = false, $version = false, $format = 'tar', $dest = '.') { $config = Factory::createConfig(); $factory = new Factory; $archiveManager = $factory->createArchiveManager($config); - $package = $this->selectPackage($io, $packageName, $version); + if ($packageName) { + $package = $this->selectPackage($io, $packageName, $version); - if (!$package) { - return 1; + if (!$package) { + return 1; + } + } else { + $package = $this->getComposer()->getPackage(); } $io->write('Creating the archive.'); diff --git a/src/Composer/Package/Archiver/ArchiveManager.php b/src/Composer/Package/Archiver/ArchiveManager.php index c3a2c818e..66aefdba6 100644 --- a/src/Composer/Package/Archiver/ArchiveManager.php +++ b/src/Composer/Package/Archiver/ArchiveManager.php @@ -16,6 +16,7 @@ use Composer\Downloader\DownloadManager; use Composer\Factory; use Composer\IO\NullIO; use Composer\Package\PackageInterface; +use Composer\Package\RootPackage; use Composer\Util\Filesystem; /** @@ -73,19 +74,24 @@ class ArchiveManager throw new \RuntimeException(sprintf('No archiver found to support %s format', $format)); } - // Directory used to download the sources $filesystem = new Filesystem(); $packageName = preg_replace('#[^a-z0-9-_.]#i', '-', $package->getPrettyString()); - $sourcePath = sys_get_temp_dir().'/composer_archiver/'.$packageName; - $filesystem->ensureDirectoryExists($sourcePath); // Archive filename $filesystem->ensureDirectoryExists($targetDir); $target = realpath($targetDir).'/'.$packageName.'.'.$format; $filesystem->ensureDirectoryExists(dirname($target)); - // Download sources - $this->downloadManager->download($package, $sourcePath, true); + if ($package instanceof RootPackage) { + $sourcePath = realpath('.'); + } else { + // Directory used to download the sources + $sourcePath = sys_get_temp_dir().'/composer_archiver/'.$packageName; + $filesystem->ensureDirectoryExists($sourcePath); + + // Download sources + $this->downloadManager->download($package, $sourcePath, true); + } // Create the archive $sourceRef = $package->getSourceReference();