1
0
Fork 0

Add links to repo to fund/licenses/search commands and add links to docs to config command

pull/10430/head
Jordi Boggiano 2022-01-05 14:16:08 +01:00
parent 06bb3c9179
commit f9d61c0665
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
7 changed files with 72 additions and 16 deletions

View File

@ -904,10 +904,19 @@ EOT
if ($showSource) { if ($showSource) {
$source = ' (' . $this->config->getSourceOfValue($k . $key) . ')'; $source = ' (' . $this->config->getSourceOfValue($k . $key) . ')';
} }
if (is_string($rawVal) && $rawVal != $value) {
$io->write('[<comment>' . $k . $key . '</comment>] <info>' . $rawVal . ' (' . $value . ')</info>' . $source, true, IOInterface::QUIET); if (null !== $k && 0 === strpos($k, 'repositories')) {
$link = 'https://getcomposer.org/doc/05-repositories.md';
} else { } else {
$io->write('[<comment>' . $k . $key . '</comment>] <info>' . $value . '</info>' . $source, true, IOInterface::QUIET); $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('[<fg=yellow;href=' . $link .'>' . $k . $key . '</>] <info>' . $rawVal . ' (' . $value . ')</info>' . $source, true, IOInterface::QUIET);
} else {
$io->write('[<fg=yellow;href=' . $link .'>' . $k . $key . '</>] <info>' . $value . '</info>' . $source, true, IOInterface::QUIET);
} }
} }
} }

View File

@ -19,6 +19,7 @@ use Composer\Package\CompletePackageInterface;
use Composer\Pcre\Preg; use Composer\Pcre\Preg;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Semver\Constraint\MatchAllConstraint;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@ -116,7 +117,7 @@ class FundCommand extends BaseCommand
$prev = $line; $prev = $line;
} }
$io->write(sprintf(' %s', $url)); $io->write(sprintf(' <href=%s>%s</>', OutputFormatter::escape($url), $url));
} }
} }

View File

@ -18,6 +18,8 @@ use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface;
use Composer\Util\PackageInfo;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -89,8 +91,15 @@ EOT
$tableStyle->setCellRowContentFormat('%s '); $tableStyle->setCellRowContentFormat('%s ');
$table->setHeaders(array('Name', 'Version', 'License')); $table->setHeaders(array('Name', 'Version', 'License'));
foreach ($packages as $package) { foreach ($packages as $package) {
$link = PackageInfo::getViewSourceOrHomepageUrl($package);
if ($link !== null) {
$name = '<href='.OutputFormatter::escape($link).'>'.$package->getPrettyName().'</>';
} else {
$name = $package->getPrettyName();
}
$table->addRow(array( $table->addRow(array(
$package->getPrettyName(), $name,
$package->getFullPrettyVersion(), $package->getFullPrettyVersion(),
implode(', ', $package instanceof CompletePackageInterface ? $package->getLicense() : array()) ?: 'none', implode(', ', $package instanceof CompletePackageInterface ? $package->getLicense() : array()) ?: 'none',
)); ));

View File

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\Factory; use Composer\Factory;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -113,7 +114,12 @@ EOT
$description = substr($description, 0, $remaining - 3) . '...'; $description = substr($description, 0, $remaining - 3) . '...';
} }
$io->write(str_pad($result['name'], $nameLength, ' ') . $warning . $description); $link = $result['url'] ?? null;
if ($link !== null) {
$io->write('<href='.OutputFormatter::escape($link).'>'.$result['name'].'</>'. str_repeat(' ', $nameLength - strlen($result['name'])) . $warning . $description);
} else {
$io->write(str_pad($result['name'], $nameLength, ' ') . $warning . $description);
}
} }
} elseif ($format === 'json') { } elseif ($format === 'json') {
$io->write(JsonFile::encode($results)); $io->write(JsonFile::encode($results));

View File

@ -40,6 +40,8 @@ use Composer\Repository\RootPackageRepository;
use Composer\Semver\Constraint\ConstraintInterface; use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Semver; use Composer\Semver\Semver;
use Composer\Spdx\SpdxLicenses; use Composer\Spdx\SpdxLicenses;
use Composer\Util\PackageInfo;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@ -439,12 +441,8 @@ EOT
$packageViewData['name'] = $package->getPrettyName(); $packageViewData['name'] = $package->getPrettyName();
if ($format !== 'json' || true !== $input->getOption('name-only')) { if ($format !== 'json' || true !== $input->getOption('name-only')) {
$packageViewData['homepage'] = $package->getHomepage(); $packageViewData['homepage'] = $package instanceof CompletePackageInterface ? $package->getHomepage() : null;
if (isset($package->getSupport()['source'])) { $packageViewData['source'] = PackageInfo::getViewSourceUrl($package);
$packageViewData['source'] = $package->getSupport()['source'];
} elseif (null !== $package->getSourceUrl()) {
$packageViewData['source'] = $package->getSourceUrl();
}
} }
$nameLength = max($nameLength, strlen($package->getPrettyName())); $nameLength = max($nameLength, strlen($package->getPrettyName()));
if ($writeVersion) { if ($writeVersion) {
@ -538,15 +536,15 @@ EOT
foreach ($packages as $package) { foreach ($packages as $package) {
$link = $package['source'] ?? $package['homepage'] ?? ''; $link = $package['source'] ?? $package['homepage'] ?? '';
if ($link) { if ($link !== '') {
$io->write($indent . '<href='.str_replace('>', '', $link).'>'.$package['name'].'</>'. str_repeat(' ', $nameLength - strlen($package['name'])), false); $io->write($indent . '<href='.OutputFormatter::escape($link).'>'.$package['name'].'</>'. str_repeat(' ', $nameLength - strlen($package['name'])), false);
} else { } else {
$io->write($indent . str_pad($package['name'], $nameLength, ' '), false); $io->write($indent . str_pad($package['name'], $nameLength, ' '), false);
} }
if (isset($package['version']) && $writeVersion) { if (isset($package['version']) && $writeVersion) {
$io->write(' ' . str_pad($package['version'], $versionLength, ' '), false); $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']; $latestVersion = $package['latest'];
$updateStatus = $package['latest-status']; $updateStatus = $package['latest-status'];
$style = $this->updateStatusToVersionStyle($updateStatus); $style = $this->updateStatusToVersionStyle($updateStatus);

View File

@ -91,7 +91,7 @@ interface RepositoryInterface extends \Countable
* @param string $type The type of package to search for. Defaults to all types of packages * @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 * @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<array{name: string, description: ?string, abandoned?: string|true}> * @phpstan-return list<array{name: string, description: ?string, abandoned?: string|true, url?: string}>
*/ */
public function search($query, $mode = 0, $type = null); public function search($query, $mode = 0, $type = null);

View File

@ -0,0 +1,33 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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);
}
}