From 0542eb98f7eb5d0334497b08a3097dea485f67f2 Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 31 May 2026 07:22:37 +0000 Subject: [PATCH] fix: accept equals form for k3s ssh options --- docs/reference/cli.md | 1 + scripts/src/ssh.ts | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 7b9a0657..2c5af5a4 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -277,6 +277,7 @@ bun scripts/cli.ts ssh G14:k3s bun scripts/cli.ts ssh G14:k3s kubectl get pipelineruns -n hwlab-ci printf 'kubectl get deploy -n hwlab-dev\n' | bun scripts/cli.ts ssh D601:k3s script bun scripts/cli.ts ssh D601:k3s:hwlab-dev:hwlab-cloud-api logs --tail 80 +bun scripts/cli.ts ssh G14:k3s logs --namespace=devops-infra --deployment=git-mirror-http --tail=80 bun scripts/cli.ts ssh D601:k3s:hwlab-dev:hwlab-cloud-api node -e 'console.log(process.version)' bun scripts/cli.ts ssh D601:k3s:hwlab-dev:hwlab-cloud-api/app pwd printf 'printf "pod=%s\n" "$HOSTNAME"\n' | bun scripts/cli.ts ssh D601:k3s:hwlab-dev:hwlab-cloud-api script diff --git a/scripts/src/ssh.ts b/scripts/src/ssh.ts index 67c978d5..9e45a4e8 100644 --- a/scripts/src/ssh.ts +++ b/scripts/src/ssh.ts @@ -1693,37 +1693,73 @@ function parseK3sTargetOptions(args: string[], commandName: string, options: Par index += 1; continue; } + const namespaceValue = k3sEqualsOptionValue(arg, "--namespace", commandName); + if (namespaceValue !== null) { + namespace = namespaceValue; + continue; + } if (arg === "--deployment" || arg === "--deploy") { resource = `deployment/${k3sOptionValue(args, index, `${commandName} ${arg}`)}`; index += 1; continue; } + const deploymentValue = k3sEqualsOptionValue(arg, "--deployment", commandName) ?? k3sEqualsOptionValue(arg, "--deploy", commandName); + if (deploymentValue !== null) { + resource = `deployment/${deploymentValue}`; + continue; + } if (arg === "--pod") { resource = `pod/${k3sOptionValue(args, index, `${commandName} ${arg}`)}`; index += 1; continue; } + const podValue = k3sEqualsOptionValue(arg, "--pod", commandName); + if (podValue !== null) { + resource = `pod/${podValue}`; + continue; + } if (arg === "--resource") { resource = normalizeK3sResource(k3sOptionValue(args, index, `${commandName} ${arg}`)); index += 1; continue; } + const resourceValue = k3sEqualsOptionValue(arg, "--resource", commandName); + if (resourceValue !== null) { + resource = normalizeK3sResource(resourceValue); + continue; + } if (arg === "--container" || arg === "-c") { container = k3sOptionValue(args, index, `${commandName} ${arg}`); index += 1; continue; } + const containerValue = k3sEqualsOptionValue(arg, "--container", commandName); + if (containerValue !== null) { + container = containerValue; + continue; + } if (arg === "--workdir" || arg === "--cwd") { workspace = k3sWorkspaceValue(k3sOptionValue(args, index, `${commandName} ${arg}`), `${commandName} ${arg}`); index += 1; continue; } + const workdirValue = k3sEqualsOptionValue(arg, "--workdir", commandName) ?? k3sEqualsOptionValue(arg, "--cwd", commandName); + if (workdirValue !== null) { + workspace = k3sWorkspaceValue(workdirValue, `${commandName} ${arg.split("=", 1)[0]}`); + continue; + } if (arg === "--shell") { if (!options.allowShell) throw new Error(`${commandName} does not support --shell`); shell = k3sScriptShell(k3sOptionValue(args, index, `${commandName} ${arg}`), `${commandName} ${arg}`); index += 1; continue; } + const shellValue = k3sEqualsOptionValue(arg, "--shell", commandName); + if (shellValue !== null) { + if (!options.allowShell) throw new Error(`${commandName} does not support --shell`); + shell = k3sScriptShell(shellValue, `${commandName} --shell`); + continue; + } if (arg === "--stdin" || arg === "-i") { stdin = true; continue; @@ -1737,11 +1773,25 @@ function parseK3sTargetOptions(args: string[], commandName: string, options: Par index += 1; continue; } + const tailValue = k3sEqualsOptionValue(arg, "--tail", commandName); + if (tailValue !== null) { + kubectlOptions.push("--tail", optionalPositiveInt(tailValue, `${commandName} --tail`)); + continue; + } if (arg === "--since" || arg === "--since-time" || arg === "--limit-bytes") { kubectlOptions.push(arg, k3sOptionValue(args, index, `${commandName} ${arg}`)); index += 1; continue; } + const sinceValue = k3sEqualsOptionValue(arg, "--since", commandName); + const sinceTimeValue = k3sEqualsOptionValue(arg, "--since-time", commandName); + const limitBytesValue = k3sEqualsOptionValue(arg, "--limit-bytes", commandName); + if (sinceValue !== null || sinceTimeValue !== null || limitBytesValue !== null) { + const optionName = sinceValue !== null ? "--since" : sinceTimeValue !== null ? "--since-time" : "--limit-bytes"; + const optionValue = sinceValue ?? sinceTimeValue ?? limitBytesValue; + kubectlOptions.push(optionName, optionValue ?? ""); + continue; + } if (arg === "--previous" || arg === "--timestamps" || arg === "--all-containers" || arg === "--prefix") { kubectlOptions.push(arg); continue; @@ -1762,6 +1812,14 @@ function parseK3sTargetOptions(args: string[], commandName: string, options: Par return { namespace, resource, container, workspace, stdin, tty, shell, command, kubectlOptions }; } +function k3sEqualsOptionValue(arg: string, option: string, commandName: string): string | null { + const prefix = `${option}=`; + if (!arg.startsWith(prefix)) return null; + const value = arg.slice(prefix.length); + if (value.length === 0) throw new Error(`${commandName} ${option} requires a value`); + return value; +} + function k3sOptionValue(args: string[], index: number, option: string): string { const value = args[index + 1]; if (value === undefined || value.length === 0) throw new Error(`${option} requires a value`);