From 5b50f32f4b42213de5e682cfb8d84a154dc29dec Mon Sep 17 00:00:00 2001 From: Julian lechner Date: Wed, 16 Sep 2026 16:54:23 +0200 Subject: [PATCH] refactor(install): share target selection helpers --- scripts/lib/install-targets.ps1 | 59 ++++++++++++++++++++++++++ scripts/lib/install-targets.sh | 73 +++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 scripts/lib/install-targets.ps1 create mode 100644 scripts/lib/install-targets.sh diff --git a/scripts/lib/install-targets.ps1 b/scripts/lib/install-targets.ps1 new file mode 100644 index 0000000..07f3288 --- /dev/null +++ b/scripts/lib/install-targets.ps1 @@ -0,0 +1,59 @@ +function Read-InstallPlatform { + param([string]$Platform) + if ($Platform) { return $Platform } + Write-Host 'Select target platform:' + Write-Host '1) Windows' + Write-Host '2) Linux' + do { $selection = Read-Host 'Selection [1-2]' } while ($selection -notin @('1','2')) + return @{'1'='Windows'; '2'='Linux'}[$selection] +} + +function Read-InstallClient { + param([string]$Client) + if ($Client) { return $Client } + Write-Host 'Select installation target:' + Write-Host '1) Codex' + Write-Host '2) Claude' + Write-Host '3) Both' + do { $selection = Read-Host 'Selection [1-3]' } while ($selection -notin @('1','2','3')) + return @{'1'='Codex'; '2'='Claude'; '3'='Both'}[$selection] +} + +function Get-InstallDestinations { + param( + [Parameter(Mandatory=$true)][string]$HomePath, + [ValidateSet('Codex','Claude','Both')][Parameter(Mandatory=$true)][string]$Client + ) + $destinations = @() + if ($Client -in @('Codex','Both')) { $destinations += Join-Path $HomePath '.codex' } + if ($Client -in @('Claude','Both')) { $destinations += Join-Path $HomePath '.claude' } + return $destinations +} + +function Get-InstallTargets { + param( + [Parameter(Mandatory=$true)][string]$Generated, + [Parameter(Mandatory=$true)][string]$HomePath, + [Parameter(Mandatory=$true)][string]$Platform, + [ValidateSet('Codex','Claude','Both')][Parameter(Mandatory=$true)][string]$Client + ) + $targets = @() + if ($Client -in @('Codex','Both')) { + $targets += @{ Source=(Join-Path $Generated "codex-$Platform"); Destination=(Join-Path $HomePath '.codex') } + $targets += @{ Source=(Join-Path $Generated "codex-$Platform/skills"); Destination=(Join-Path $HomePath '.agents/skills') } + } + if ($Client -in @('Claude','Both')) { + $targets += @{ Source=(Join-Path $Generated "claude-$Platform"); Destination=(Join-Path $HomePath '.claude') } + } + return $targets +} + +function Test-AnyManifestPresent { + param([Parameter(Mandatory=$true)][string[]]$Destinations) + return [bool](@($Destinations | Where-Object { Test-Path (Get-ManagedManifestPath $_) }).Count) +} + +function Test-AllManifestsPresent { + param([Parameter(Mandatory=$true)][string[]]$Destinations) + return [bool](@($Destinations | Where-Object { -not (Test-Path (Get-ManagedManifestPath $_)) }).Count -eq 0) +} diff --git a/scripts/lib/install-targets.sh b/scripts/lib/install-targets.sh new file mode 100644 index 0000000..6f307c0 --- /dev/null +++ b/scripts/lib/install-targets.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +read_install_platform() { + local platform=$1 + if [ -n "$platform" ]; then + case "$platform" in + windows|Windows) printf 'windows\n'; return 0 ;; + linux|Linux) printf 'linux\n'; return 0 ;; + *) printf 'Unknown --platform value: %s (expected windows or linux)\n' "$platform" >&2; return 1 ;; + esac + fi + printf 'Select target platform:\n1) Windows\n2) Linux\n' >&2 + local selection + while :; do + read -r -p 'Selection [1-2] ' selection + case "$selection" in 1) printf 'windows\n'; return 0 ;; 2) printf 'linux\n'; return 0 ;; esac + done +} + +read_install_client() { + local client=$1 + if [ -n "$client" ]; then + case "$client" in + codex|Codex) printf 'codex\n'; return 0 ;; + claude|Claude) printf 'claude\n'; return 0 ;; + both|Both) printf 'both\n'; return 0 ;; + *) printf 'Unknown --client value: %s (expected codex, claude, or both)\n' "$client" >&2; return 1 ;; + esac + fi + printf 'Select installation target:\n1) Codex\n2) Claude\n3) Both\n' >&2 + local selection + while :; do + read -r -p 'Selection [1-3] ' selection + case "$selection" in 1) printf 'codex\n'; return 0 ;; 2) printf 'claude\n'; return 0 ;; 3) printf 'both\n'; return 0 ;; esac + done +} + +# get_install_destinations -- prints one destination per line +get_install_destinations() { + local home_path=$1 client=$2 + case "$client" in codex|both) printf '%s/.codex\n' "$home_path" ;; esac + case "$client" in claude|both) printf '%s/.claude\n' "$home_path" ;; esac +} + +# get_install_targets -- prints "source|dest" per line +get_install_targets() { + local generated=$1 home_path=$2 platform=$3 client=$4 + case "$client" in + codex|both) + printf '%s/codex-%s|%s/.codex\n' "$generated" "$platform" "$home_path" + printf '%s/codex-%s/skills|%s/.agents/skills\n' "$generated" "$platform" "$home_path" + ;; + esac + case "$client" in claude|both) printf '%s/claude-%s|%s/.claude\n' "$generated" "$platform" "$home_path" ;; esac +} + +# any_manifest_present ... -- true (0) if at least one has a manifest +any_manifest_present() { + local destination + for destination in "$@"; do + [ -f "$(manifest_path "$destination")" ] && return 0 + done + return 1 +} + +# all_manifests_present ... -- true (0) only if every destination has a manifest +all_manifests_present() { + local destination + for destination in "$@"; do + [ -f "$(manifest_path "$destination")" ] || return 1 + done + return 0 +}