update lock clucknut
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 14s
Build, Push and Deploy / build-and-push (push) Successful in 3m14s
Build, Push and Deploy / deploy-staging (push) Successful in 25s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-18 20:32:18 +07:00
parent 4554035227
commit dcaf267458
3359 changed files with 153185 additions and 205489 deletions

View File

@@ -3,7 +3,7 @@
/*
* This file is part of Psy Shell.
*
* (c) 2012-2025 Justin Hileman
* (c) 2012-2026 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,7 +11,9 @@
namespace Psy\Command;
use Psy\Output\ShellOutput;
use Psy\Formatter\ManualWrapper;
use Psy\Readline\Interactive\Layout\DisplayString;
use Psy\Util\Tty;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -24,7 +26,12 @@
*/
class HelpCommand extends Command
{
private const TABLE_OVERHEAD_TWO_COLUMNS = 7;
private const TABLE_OVERHEAD_THREE_COLUMNS = 10;
private const MIN_DESCRIPTION_WIDTH_FOR_ALIAS_COLUMN = 40;
private ?Command $command = null;
private ?InputInterface $commandInput = null;
/**
* {@inheritdoc}
@@ -51,6 +58,14 @@ public function setCommand(Command $command)
$this->command = $command;
}
/**
* Helper for preserving the original input when rendering contextual help.
*/
public function setCommandInput(InputInterface $input): void
{
$this->commandInput = $input;
}
/**
* {@inheritdoc}
*
@@ -58,10 +73,13 @@ public function setCommand(Command $command)
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$shellOutput = $this->shellOutput($output);
if ($this->command !== null) {
// help for an individual command
$output->page($this->command->asText());
$shellOutput->page($this->command->asTextForInput($this->commandInput ?? $input));
$this->command = null;
$this->commandInput = null;
} elseif ($name = $input->getArgument('command_name')) {
// help for an individual command
try {
@@ -78,42 +96,93 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}
$output->page($cmd->asText());
if (!$cmd instanceof Command) {
throw new \RuntimeException(\sprintf('Expected Psy\Command\Command instance, got %s', \get_class($cmd)));
}
$shellOutput->page($cmd->asTextForInput($input));
} else {
// list available commands
$commands = $this->getApplication()->all();
$table = $this->getTable($output);
foreach ($commands as $name => $command) {
if ($name !== $command->getName()) {
continue;
}
if ($command->getAliases()) {
$aliases = \sprintf('<comment>Aliases:</comment> %s', \implode(', ', $command->getAliases()));
} else {
$aliases = '';
}
$table->addRow([
\sprintf('<info>%s</info>', $name),
$command->getDescription(),
$aliases,
]);
}
if ($output instanceof ShellOutput) {
$output->startPaging();
}
$table->render();
if ($output instanceof ShellOutput) {
$output->stopPaging();
}
$this->commandInput = null;
$shellOutput->page(function (OutputInterface $pagedOutput): void {
$this->renderCommandList($pagedOutput);
});
}
return 0;
}
/**
* Render the top-level command list with fixed command widths and a
* conditional alias column when the terminal is wide enough.
*/
private function renderCommandList(OutputInterface $output): void
{
$commands = [];
foreach ($this->getApplication()->all() as $name => $command) {
if ($name !== $command->getName()) {
continue;
}
$commands[] = [
'name' => $name,
'description' => $command->getDescription(),
'aliasText' => $command->getAliases()
? \sprintf('<comment>Aliases:</comment> %s', \implode(', ', $command->getAliases()))
: '',
];
}
$nameWidth = 0;
$aliasWidth = 0;
$descriptionWidth = 0;
$formatter = $output->getFormatter();
foreach ($commands as $command) {
$nameWidth = \max($nameWidth, DisplayString::width($command['name']));
$aliasWidth = \max($aliasWidth, DisplayString::widthWithoutFormatting($command['aliasText'], $formatter));
$descriptionWidth = \max($descriptionWidth, DisplayString::width($command['description']));
}
$terminalWidth = Tty::getWidth();
$wrapper = new ManualWrapper();
$table = $this->getTable($output)->setColumnWidth(0, $nameWidth);
$descriptionWidthWithAliasColumn = $terminalWidth - $nameWidth - $aliasWidth - self::TABLE_OVERHEAD_THREE_COLUMNS;
if ($aliasWidth > 0 && $descriptionWidthWithAliasColumn >= self::MIN_DESCRIPTION_WIDTH_FOR_ALIAS_COLUMN) {
$descriptionColumnWidth = \min($descriptionWidth, $descriptionWidthWithAliasColumn);
$table
->setColumnWidth(1, $descriptionColumnWidth)
->setColumnWidth(2, $aliasWidth);
foreach ($commands as $command) {
$table->addRow([
\sprintf('<info>%s</info>', $command['name']),
$wrapper->wrap($command['description'], $descriptionColumnWidth),
$command['aliasText'],
]);
}
$table->render();
return;
}
$detailsWidth = \max(10, $terminalWidth - $nameWidth - self::TABLE_OVERHEAD_TWO_COLUMNS);
$table->setColumnWidth(1, $detailsWidth);
foreach ($commands as $command) {
$details = $wrapper->wrap($command['description'], $detailsWidth);
if ($command['aliasText'] !== '') {
$details .= "\n".$wrapper->wrap($command['aliasText'], $detailsWidth);
}
$table->addRow([
\sprintf('<info>%s</info>', $command['name']),
$details,
]);
}
$table->render();
}
}