@ -1396,7 +1396,7 @@ action="${1:-}"
[[ $# -gt 0 ]] && shift
[[ $# -gt 0 ]] && shift
platform_opt=" "
platform_opt=" "
case " $action " in
case " $action " in
fetch| list| use)
fetch| list| use| platforms )
newargs=()
newargs=()
while [[ $# -gt 0 ]]; do
while [[ $# -gt 0 ]]; do
if [[ " $ 1 " == " -platform " ]]; then
if [[ " $ 1 " == " -platform " ]]; then
@ -1512,11 +1512,12 @@ metadata_summary() {
#operator help (the 'help' action; the no-args case shows show_usage only).
#operator help (the 'help' action; the no-args case shows show_usage only).
#Keep in sync with the ps1 payload's Show-PunkRuntimeHelp/Show-PunkRuntimeUsage.
#Keep in sync with the ps1 payload's Show-PunkRuntimeHelp/Show-PunkRuntimeUsage.
show_usage() {
show_usage() {
echo " Usage: $0 {fetch|list|use|run|help} "
echo " Usage: $0 {fetch|list|use|run|platforms| help} "
echo " fetch ?<name>? ?-platform <p>? download+verify a runtime from punkbin "
echo " fetch ?<name>? ?-platform <p>? download+verify a runtime from punkbin "
echo " list ?-remote? ?-platform <p>? installed (or server) runtimes + metadata "
echo " list ?-remote? ?-platform <p>? installed (or server) runtimes + metadata "
echo " use <name> ?-platform <p>? select active / materialize -r<N> artifact "
echo " use <name> ?-platform <p>? select active / materialize -r<N> artifact "
echo " run ?args...? launch the active local-platform runtime "
echo " run ?args...? launch the active local-platform runtime "
echo " platforms ?-remote? local platform folders / platforms the server serves "
echo " help full help (options, env vars, examples) "
echo " help full help (options, env vars, examples) "
}
}
show_help() {
show_help() {
@ -1548,6 +1549,13 @@ show_help() {
echo " Resolution: PUNK_ACTIVE_RUNTIME env > active.toml > sole "
echo " Resolution: PUNK_ACTIVE_RUNTIME env > active.toml > sole "
echo " installed candidate. Takes no -platform (foreign binaries are "
echo " installed candidate. Takes no -platform (foreign binaries are "
echo " not runnable here). "
echo " not runnable here). "
echo " platforms ?-remote? "
echo " List local platform folders under bin/runtime/. With -remote, "
echo " list the platforms the artifact server serves - read from the "
echo " server's platforms.txt discovery manifest (part of the punkbin "
echo " layout; third-party mirrors carry the same file), with local "
echo " presence marked. Servers without the manifest get an actionable "
echo " message (name platforms explicitly with -platform). "
echo " "
echo " "
echo " Platforms: punkbin platform-dir names (e.g win32-x86_64, linux-x86_64, "
echo " Platforms: punkbin platform-dir names (e.g win32-x86_64, linux-x86_64, "
echo " macosx) - not zig triples. Default is the local platform; override "
echo " macosx) - not zig triples. Default is the local platform; override "
@ -1561,6 +1569,7 @@ show_help() {
echo " PUNK_ACTIVE_RUNTIME (run-time selection override) "
echo " PUNK_ACTIVE_RUNTIME (run-time selection override) "
echo " "
echo " "
echo " Examples: "
echo " Examples: "
echo " $0 platforms -remote "
echo " $0 fetch tclsh9.0.5-punk-r1.exe "
echo " $0 fetch tclsh9.0.5-punk-r1.exe "
echo " $0 use tclsh9.0.5-punk-r1.exe (materializes tclsh9.0.5-punk.exe) "
echo " $0 use tclsh9.0.5-punk-r1.exe (materializes tclsh9.0.5-punk.exe) "
echo " $0 list -remote -platform linux-x86_64 "
echo " $0 list -remote -platform linux-x86_64 "
@ -1854,6 +1863,77 @@ case "$action" in
#exactly the runtime's argument list)
#exactly the runtime's argument list)
$activeruntime_fullpath " $@ "
$activeruntime_fullpath " $@ "
;;
;;
" platforms " )
#enumerate platform folders: local (bin/runtime/*) and, with -remote, the
#server's platforms.txt discovery manifest (raw-file servers have no
#directory listing - the manifest is part of the punkbin layout contract;
#third-party mirrors carry the same file). -platform is ignored here
#(this action enumerates ALL platforms).
rtroot=" ${scriptdir}/runtime "
localdirs=" "
if [[ - d " $ r t r o o t " ] ] ; t h e n
localdirs=$(ls -1 " $rtroot " 2 > /dev/null | while read -r d; do [[ -d " $rtroot/$d " ]] && echo " $d " ; done)
fi
if [[ " $ { 1 : - } " == " -remote " ]]; then
manifesturl=" ${url_kitbase}/platforms.txt "
manifestlocal=" ${rtroot}/platforms.txt "
mkdir -p " $rtroot "
if curl - f s S L - - o u t p u t " $ m a n i f e s t l o c a l " " $ m a n i f e s t u r l " ; t h e n
echo " Fetched $manifesturl "
elif [[ -f " $manifestlocal " ]]; then
echo " WARNING: could not fetch $manifesturl - using cached copy at $manifestlocal "
else
echo " No platforms.txt available from $manifesturl "
echo " (pre-convention punkbin or third-party mirror without the discovery manifest) "
echo " Name platforms explicitly with -platform; canonical names: 'help platforms' in the punk shell "
exit 1
fi
echo " ----------------------------------------------------------------------- "
echo " Platforms served by ${url_kitbase} "
echo " ----------------------------------------------------------------------- "
remoteplatforms=" "
while IFS= read -r line; do
line=" ${line# " ${line%% [![:space:]]*}" } "
[[ -z " $line " || " ${line:0:1} " == " # " ]] && continue
remoteplatforms=" $remoteplatforms $line "
marks=" "
[[ " $line " == " $local_platform " ]] && marks=" local platform "
if printf ' % s \ n ' $ l o c a l d i r s | g r e p - q x " $ l i n e " ; t h e n
[[ -n " $marks " ]] && marks=" $marks, "
marks=" ${marks}local dir present "
fi
if [[ - n " $ m a r k s " ] ] ; t h e n
printf ' %-25s (% s)\n' " $line " " $marks "
else
printf ' %-25s\n' " $line "
fi
done < " $manifestlocal "
for d in $localdirs; do
if ! p r i n t f ' % s \ n ' $ r e m o t e p l a t f o r m s | g r e p - q x " $ d " ; t h e n
printf ' %-25s (local dir only - not served remotely)\n' " $d "
fi
done
echo " ----------------------------------------------------------------------- "
echo " Use: '$0 list -remote -platform <name>' to see a platform's runtimes "
else
echo " ----------------------------------------------------------------------- "
echo " Local platform folders under $rtroot "
echo " ----------------------------------------------------------------------- "
if [[ - z " $ l o c a l d i r s " ] ] ; t h e n
echo " (none - 'fetch' creates the local platform's folder) "
fi
for d in $localdirs; do
if [[ " $ d " == " $local_platform " ]]; then
printf '* %-25s (local platform)\n' " $d "
else
printf ' %-25s\n' " $d "
fi
done
echo " ----------------------------------------------------------------------- "
echo " Use: '$0 platforms -remote' to see platforms served by the artifact server "
echo " Canonical platform names: 'help platforms' in the punk shell "
fi
;;
" help " )
" help " )
show_help
show_help
;;
;;
@ -2241,11 +2321,12 @@ function Get-PunkRuntimeCandidates {
#operator help (the 'help' action; the no-args case shows the Usage block only).
#operator help (the 'help' action; the no-args case shows the Usage block only).
#Keep in sync with the bash payload's show_help/show_usage.
#Keep in sync with the bash payload's show_help/show_usage.
function Show-PunkRuntimeUsage {
function Show-PunkRuntimeUsage {
write-host " Usage: punk-runtime.cmd {fetch|list|use|run|help} "
write-host " Usage: punk-runtime.cmd {fetch|list|use|run|platforms| help} "
write-host " fetch ?<name>? ?-platform <p>? download+verify a runtime from punkbin "
write-host " fetch ?<name>? ?-platform <p>? download+verify a runtime from punkbin "
write-host " list ?-remote? ?-platform <p>? installed (or server) runtimes + metadata "
write-host " list ?-remote? ?-platform <p>? installed (or server) runtimes + metadata "
write-host " use <name> ?-platform <p>? select active / materialize -r<N> artifact "
write-host " use <name> ?-platform <p>? select active / materialize -r<N> artifact "
write-host " run ?args...? launch the active local-platform runtime "
write-host " run ?args...? launch the active local-platform runtime "
write-host " platforms ?-remote? local platform folders / platforms the server serves "
write-host " help full help (options, env vars, examples) "
write-host " help full help (options, env vars, examples) "
}
}
function Show-PunkRuntimeHelp {
function Show-PunkRuntimeHelp {
@ -2277,6 +2358,13 @@ function Show-PunkRuntimeHelp {
write-host " Resolution: PUNK_ACTIVE_RUNTIME env > active.toml > sole "
write-host " Resolution: PUNK_ACTIVE_RUNTIME env > active.toml > sole "
write-host " installed candidate. Takes no -platform (foreign binaries are "
write-host " installed candidate. Takes no -platform (foreign binaries are "
write-host " not runnable here). "
write-host " not runnable here). "
write-host " platforms ?-remote? "
write-host " List local platform folders under bin/runtime/. With -remote, "
write-host " list the platforms the artifact server serves - read from the "
write-host " server's platforms.txt discovery manifest (part of the punkbin "
write-host " layout; third-party mirrors carry the same file), with local "
write-host " presence marked. Servers without the manifest get an actionable "
write-host " message (name platforms explicitly with -platform). "
write-host " "
write-host " "
write-host " Platforms: punkbin platform-dir names (e.g win32-x86_64, linux-x86_64, "
write-host " Platforms: punkbin platform-dir names (e.g win32-x86_64, linux-x86_64, "
write-host " macosx) - not zig triples. Default is the local platform; override "
write-host " macosx) - not zig triples. Default is the local platform; override "
@ -2290,6 +2378,7 @@ function Show-PunkRuntimeHelp {
write-host " PUNK_ACTIVE_RUNTIME (run-time selection override) "
write-host " PUNK_ACTIVE_RUNTIME (run-time selection override) "
write-host " "
write-host " "
write-host " Examples: "
write-host " Examples: "
write-host " punk-runtime.cmd platforms -remote "
write-host " punk-runtime.cmd fetch tclsh9.0.5-punk-r1.exe "
write-host " punk-runtime.cmd fetch tclsh9.0.5-punk-r1.exe "
write-host " punk-runtime.cmd use tclsh9.0.5-punk-r1.exe (materializes tclsh9.0.5-punk.exe) "
write-host " punk-runtime.cmd use tclsh9.0.5-punk-r1.exe (materializes tclsh9.0.5-punk.exe) "
write-host " punk-runtime.cmd list -remote -platform linux-x86_64 "
write-host " punk-runtime.cmd list -remote -platform linux-x86_64 "
@ -2380,7 +2469,9 @@ function psmain {
[Parameter(Mandatory=$false, Position = 0)][string] $action = " "
[Parameter(Mandatory=$false, Position = 0)][string] $action = " "
)
)
dynamicparam {
dynamicparam {
if ($action - e q ' l i s t ' ) {
if ($action - e q ' l i s t ' - o r $ a c t i o n - e q ' p l a t f o r m s ' ) {
#shared dynamic params: -remote for both; -platform is meaningful to
#'list' and ignored by 'platforms' (which enumerates ALL platforms)
$parameterAttribute = [System.Management.Automation.ParameterAttribute]@{
$parameterAttribute = [System.Management.Automation.ParameterAttribute]@{
ParameterSetName = " listruntime "
ParameterSetName = " listruntime "
Mandatory = $false
Mandatory = $false
@ -2477,7 +2568,7 @@ function psmain {
'action' {
'action' {
write-host " got action " $PSBoundParameters.action
write-host " got action " $PSBoundParameters.action
Set-Variable -Name $_ -Value $PSBoundParameters." $_ "
Set-Variable -Name $_ -Value $PSBoundParameters." $_ "
$known_actions = @(" fetch " , " list " , " use " , " run " , " help " )
$known_actions = @(" fetch " , " list " , " use " , " run " , " platforms " , " help" )
if (-not($known_actions - c o n t a i n s $ a c t i o n ) ) {
if (-not($known_actions - c o n t a i n s $ a c t i o n ) ) {
write-host " action '$action' not understood. Known_actions: $known_actions "
write-host " action '$action' not understood. Known_actions: $known_actions "
exit 1
exit 1
@ -2903,6 +2994,83 @@ function psmain {
}
}
}
}
}
}
'platforms' {
#enumerate platform folders: local (bin/runtime/*) and, with
#-remote, the server's platforms.txt discovery manifest (raw-file
#servers have no directory listing - the manifest is part of the
#punkbin layout contract; third-party mirrors carry the same file)
$localdirs = @()
if (Test-Path - P a t h $ r t f o l d e r - P a t h T y p e C o n t a i n e r ) {
$localdirs = @(Get-ChildItem -Path $rtfolder -Directory | Select-Object -ExpandProperty Name | Sort-Object)
}
if ( $ P S B o u n d P a r a m e t e r s . C o n t a i n s K e y ( ' r e m o t e ' ) ) {
$manifesturl = " $artifacturl/platforms.txt "
$manifestlocal = Join-Path -Path $rtfolder -ChildPath " platforms.txt "
if (-not ( T e s t - P a t h - P a t h $ r t f o l d e r - P a t h T y p e C o n t a i n e r ) ) {
new-item -Path $rtfolder -ItemType Directory -force | out-null
}
try {
Invoke-WebRequest -Uri $manifesturl -OutFile $manifestlocal -ErrorAction Stop
Write-Host " Fetched $manifesturl "
} catch {
if (Test-Path - P a t h $ m a n i f e s t l o c a l - P a t h T y p e L e a f ) {
Write-Host " WARNING: could not fetch ${manifesturl}: $($_.Exception.Message) "
Write-Host " WARNING: using cached copy at $manifestlocal "
} else {
Write-Host " No platforms.txt available from ${manifesturl}: $($_.Exception.Message) "
Write-Host " (pre-convention punkbin or third-party mirror without the discovery manifest) "
Write-Host " Name platforms explicitly with -platform; canonical names: 'help platforms' in the punk shell "
exit 1
}
}
$remoteplatforms = @()
foreach ($line in (Get-Content -Path $manifestlocal)) {
$line = $line.Trim()
if ($line - e q " " - o r $ l i n e . S t a r t s W i t h ( " # " ) ) { c o n t i n u e }
$remoteplatforms += $line
}
Write-host " ----------------------------------------------------------------------- "
Write-Host " Platforms served by $artifacturl "
Write-host " ----------------------------------------------------------------------- "
foreach ($p in $remoteplatforms) {
$marks = @()
if ($p - e q $ s c r i p t : P u n k L o c a l P l a t f o r m ) { $ m a r k s + = " l o c a l p l a t f o r m " }
if ($localdirs - c o n t a i n s $ p ) { $ m a r k s + = " l o c a l d i r p r e s e n t " }
$lhs = " $p " .PadRight(25, ' ')
if ($marks.Count - g t 0 ) {
write-host " $lhs ($($marks -join ', ')) "
} else {
write-host " $lhs "
}
}
foreach ($d in $localdirs) {
if (-not ( $ r e m o t e p l a t f o r m s - c o n t a i n s $ d ) ) {
$lhs = " $d " .PadRight(25, ' ')
write-host " $lhs (local dir only - not served remotely) "
}
}
Write-host " ----------------------------------------------------------------------- "
Write-Host " Use: 'list -remote -platform <name>' to see a platform's runtimes "
} else {
Write-host " ----------------------------------------------------------------------- "
Write-Host " Local platform folders under $rtfolder "
Write-host " ----------------------------------------------------------------------- "
if ($localdirs.Count - e q 0 ) {
write-host " (none - 'fetch' creates the local platform's folder) "
}
foreach ($d in $localdirs) {
$lhs = " $d " .PadRight(25, ' ')
if ($d - e q $ s c r i p t : P u n k L o c a l P l a t f o r m ) {
write-host " * $lhs (local platform) "
} else {
write-host " $lhs "
}
}
Write-host " ----------------------------------------------------------------------- "
Write-Host " Use: 'platforms -remote' to see platforms served by the artifact server "
Write-Host " Canonical platform names: 'help platforms' in the punk shell "
}
}
'help' {
'help' {
Show-PunkRuntimeHelp
Show-PunkRuntimeHelp
}
}