From 8fd4c47dfd2b20de43fa021f516c3d900037ab90 Mon Sep 17 00:00:00 2001 From: Gunjan Vyas Date: Wed, 22 Jul 2026 17:50:43 +0530 Subject: [PATCH] docs: fix make.ps1 hanging when Out-String wraps help on narrow consoles Out-String breaks long help lines on smaller consoles (such as CI runners), so command discovery mis-parses wrapped description text as subcommands and docs can recurse forever. Parse as remote-docs.sh Signed-off-by: Gunjan Vyas --- docs/make.ps1 | 53 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/docs/make.ps1 b/docs/make.ps1 index 27289aae7f..b452c2d891 100644 --- a/docs/make.ps1 +++ b/docs/make.ps1 @@ -14,32 +14,47 @@ function Get-Podman-Commands-List{ Write-Host "Retrieving the list of ""podman"" commands." } + $helpLines = @(Invoke-Expression "$podmanClient $podmanHelpCommand") + # Retrieve the list of subcommands of $command # e.g. "podman help machine" returns the list of # "podman machine" subcommands: info, init, etc... $subCommands = @() - $subCommands = Invoke-Expression "$podmanClient $podmanHelpCommand" | - Select-String -Pattern "^\s*Available Commands:" -Context 0, 1000 | Out-String -Stream | - Select-String -Pattern "^\s+$" -Context 1000, 0 | Out-String -Stream | - Select-String -Pattern ">\s*Available Commands:|^>\s*$|^\s*$" -NotMatch | Out-String -Stream | - ForEach-Object { $_ -replace '^\s*(\w+)\s+.*$', '$1' } | Where-Object { $_ -ne "" } - - if ($command) { - $subCommands = $subCommands | ForEach-Object { "$command $_" } - } - - # Recursively get the list of sub-subcommands for each subcommand - foreach ($subCommand in $subCommands) { - - $subSubCommands = @() - $subSubCommands = Get-Podman-Commands-List -podmanClient "$podmanClient" -command "${subCommand}" - - if ($subSubCommands) { - $subCommands += $subSubCommands + $inCommands = $false + foreach ($line in $helpLines) { + if ($line -match "^\s*Available Commands:\s*$") { + $inCommands = $true + continue + } + # end of commands list + if ($inCommands -and $line -match '^\s*Options:\s*$') { + break + } + if (!$inCommands) { + continue + } + # add command to list + $name = ($line.Trim() -Split '\s+')[0] + if ($name -and $name -ne 'help') { + $subCommands += $name } } - return $subCommands + if ($command) { + $subCommands = @($subCommands | ForEach-Object { "$command $_" }) + } else { + $subCommands = @($subCommands) + } + + $allCommands = @($subCommands) + foreach ($subCommand in $subCommands) { + $subSubCommands = @(Get-Podman-Commands-List -podmanClient "$podmanClient" -command "${subCommand}") + if ($subSubCommands) { + $allCommands += $subSubCommands + } + } + + return $allCommands } function Build-Podman-For-Windows-HTML-Page{