diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index e51ba1a7ca01..b843a9c7020c 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -904,10 +904,19 @@ protected function listConfiguration(array $contents, array $rawContents, Output if ($showSource) { $source = ' (' . $this->config->getSourceOfValue($k . $key) . ')'; } + + if (null !== $k && 0 === strpos($k, 'repositories')) { + $link = 'https://getcomposer.org/doc/05-repositories.md'; + } else { + $id = Preg::replace('{\..*$}', '', $k === '' || $k === null ? (string) $key : $k); + $id = Preg::replace('{[^a-z0-9]}i', '-', strtolower(trim($id))); + $id = Preg::replace('{-+}', '-', $id); + $link = 'https://getcomposer.org/doc/06-config.md#' . $id; + } if (is_string($rawVal) && $rawVal != $value) { - $io->write('[' . $k . $key . '] ' . $rawVal . ' (' . $value . ')' . $source, true, IOInterface::QUIET); + $io->write('[' . $k . $key . '] ' . $rawVal . ' (' . $value . ')' . $source, true, IOInterface::QUIET); } else { - $io->write('[' . $k . $key . '] ' . $value . '' . $source, true, IOInterface::QUIET); + $io->write('[' . $k . $key . '] ' . $value . '' . $source, true, IOInterface::QUIET); } } } diff --git a/src/Composer/Command/FundCommand.php b/src/Composer/Command/FundCommand.php index 96c2c25d8e78..d8bccb6200a3 100644 --- a/src/Composer/Command/FundCommand.php +++ b/src/Composer/Command/FundCommand.php @@ -19,6 +19,7 @@ use Composer\Pcre\Preg; use Composer\Repository\CompositeRepository; use Composer\Semver\Constraint\MatchAllConstraint; +use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -116,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $prev = $line; } - $io->write(sprintf(' %s', $url)); + $io->write(sprintf(' %s', OutputFormatter::escape($url), $url)); } } diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index 3c7c8265e37f..a50a6bae8969 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -18,6 +18,8 @@ use Composer\Plugin\PluginEvents; use Composer\Package\PackageInterface; use Composer\Repository\RepositoryInterface; +use Composer\Util\PackageInfo; +use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -89,8 +91,15 @@ protected function execute(InputInterface $input, OutputInterface $output) $tableStyle->setCellRowContentFormat('%s '); $table->setHeaders(array('Name', 'Version', 'License')); foreach ($packages as $package) { + $link = PackageInfo::getViewSourceOrHomepageUrl($package); + if ($link !== null) { + $name = ''.$package->getPrettyName().''; + } else { + $name = $package->getPrettyName(); + } + $table->addRow(array( - $package->getPrettyName(), + $name, $package->getFullPrettyVersion(), implode(', ', $package instanceof CompletePackageInterface ? $package->getLicense() : array()) ?: 'none', )); diff --git a/src/Composer/Command/SearchCommand.php b/src/Composer/Command/SearchCommand.php index 285fd4221ca2..04d5e549dda0 100644 --- a/src/Composer/Command/SearchCommand.php +++ b/src/Composer/Command/SearchCommand.php @@ -14,6 +14,7 @@ use Composer\Factory; use Composer\Json\JsonFile; +use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -113,7 +114,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $description = substr($description, 0, $remaining - 3) . '...'; } - $io->write(str_pad($result['name'], $nameLength, ' ') . $warning . $description); + $link = $result['url'] ?? null; + if ($link !== null) { + $io->write(''.$result['name'].''. str_repeat(' ', $nameLength - strlen($result['name'])) . $warning . $description); + } else { + $io->write(str_pad($result['name'], $nameLength, ' ') . $warning . $description); + } } } elseif ($format === 'json') { $io->write(JsonFile::encode($results)); diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index f1f52f90b7a2..5f89c0d866c8 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -40,6 +40,8 @@ use Composer\Semver\Constraint\ConstraintInterface; use Composer\Semver\Semver; use Composer\Spdx\SpdxLicenses; +use Composer\Util\PackageInfo; +use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -326,6 +328,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } // list packages + /** @var array> $packages */ $packages = array(); $packageFilterRegex = null; if (null !== $packageFilter) { @@ -437,6 +440,10 @@ protected function execute(InputInterface $input, OutputInterface $output) } $packageViewData['name'] = $package->getPrettyName(); + if ($format !== 'json' || true !== $input->getOption('name-only')) { + $packageViewData['homepage'] = $package instanceof CompletePackageInterface ? $package->getHomepage() : null; + $packageViewData['source'] = PackageInfo::getViewSourceUrl($package); + } $nameLength = max($nameLength, strlen($package->getPrettyName())); if ($writeVersion) { $packageViewData['version'] = $package->getFullPrettyVersion(); @@ -528,11 +535,16 @@ protected function execute(InputInterface $input, OutputInterface $output) } foreach ($packages as $package) { - $io->write($indent . str_pad($package['name'], $nameLength, ' '), false); + $link = $package['source'] ?? $package['homepage'] ?? ''; + if ($link !== '') { + $io->write($indent . ''.$package['name'].''. str_repeat(' ', $nameLength - strlen($package['name'])), false); + } else { + $io->write($indent . str_pad($package['name'], $nameLength, ' '), false); + } if (isset($package['version']) && $writeVersion) { $io->write(' ' . str_pad($package['version'], $versionLength, ' '), false); } - if (isset($package['latest']) && $writeLatest) { + if (isset($package['latest']) && isset($package['latest-status']) && $writeLatest) { $latestVersion = $package['latest']; $updateStatus = $package['latest-status']; $style = $this->updateStatusToVersionStyle($updateStatus); diff --git a/src/Composer/Repository/RepositoryInterface.php b/src/Composer/Repository/RepositoryInterface.php index 7972e9417c47..9debf589dd82 100644 --- a/src/Composer/Repository/RepositoryInterface.php +++ b/src/Composer/Repository/RepositoryInterface.php @@ -91,7 +91,7 @@ public function loadPackages(array $packageNameMap, array $acceptableStabilities * @param string $type The type of package to search for. Defaults to all types of packages * * @return array[] an array of array('name' => '...', 'description' => '...'|null, 'abandoned' => 'string'|true|unset) For SEARCH_VENDOR the name will be in "vendor" form - * @phpstan-return list + * @phpstan-return list */ public function search($query, $mode = 0, $type = null); diff --git a/src/Composer/Util/PackageInfo.php b/src/Composer/Util/PackageInfo.php new file mode 100644 index 000000000000..84277c731cb3 --- /dev/null +++ b/src/Composer/Util/PackageInfo.php @@ -0,0 +1,33 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Util; + +use Composer\Package\CompletePackageInterface; +use Composer\Package\PackageInterface; + +class PackageInfo +{ + public static function getViewSourceUrl(PackageInterface $package): ?string + { + if ($package instanceof CompletePackageInterface && isset($package->getSupport()['source'])) { + return $package->getSupport()['source']; + } + + return $package->getSourceUrl(); + } + + public static function getViewSourceOrHomepageUrl(PackageInterface $package): ?string + { + return self::getViewSourceUrl($package) ?? ($package instanceof CompletePackageInterface ? $package->getHomepage() : null); + } +}