fix: stream runner tran ssh output
This commit is contained in:
+32
-2
@@ -39,7 +39,7 @@ export interface SshFailureHint {
|
||||
note: string;
|
||||
}
|
||||
|
||||
const argvQuotedSshSubcommands = new Set(["rg", "grep", "sed", "nl", "stat", "du", "ls", "cat", "head", "tail", "wc", "pwd"]);
|
||||
const argvQuotedSshSubcommands = new Set(["git", "rg", "grep", "sed", "nl", "stat", "du", "ls", "cat", "head", "tail", "wc", "pwd"]);
|
||||
const nativeK3sKubeconfig = "/etc/rancher/k3s/k3s.yaml";
|
||||
const k3sResourceKindAliases = new Set(["pod", "po", "pods", "deployment", "deploy", "deployments", "statefulset", "sts", "daemonset", "ds", "job", "jobs"]);
|
||||
const legacyK3sOperationRouteSegments = new Set([
|
||||
@@ -1018,7 +1018,12 @@ function parseK3sTargetOperation(route: ParsedSshRoute, args: string[]): ParsedS
|
||||
}
|
||||
if (operation === "kubectl") throw new Error(`ssh k3s kubectl is a control-plane operation; use ssh ${route.providerId}:k3s kubectl ...`);
|
||||
if (operation === "exec") {
|
||||
return { remoteCommand: buildK3sExecCommand([...targetArgs, ...k3sRouteCommandArgs(operationArgs)]), requiresStdin: false, invocationKind: "helper" };
|
||||
const execArgs = k3sRouteExecOperationArgs(operationArgs);
|
||||
return {
|
||||
remoteCommand: buildK3sExecCommand([...targetArgs, ...execArgs]),
|
||||
requiresStdin: execArgs.includes("--stdin") || execArgs.includes("-i"),
|
||||
invocationKind: "helper",
|
||||
};
|
||||
}
|
||||
return { remoteCommand: buildK3sExecCommand([...targetArgs, ...k3sRouteCommandArgs(args)]), requiresStdin: false, invocationKind: "helper" };
|
||||
}
|
||||
@@ -1045,6 +1050,31 @@ function k3sRouteCommandArgs(args: string[]): string[] {
|
||||
return args[0] === "--" ? args : ["--", ...args];
|
||||
}
|
||||
|
||||
function k3sRouteExecOperationArgs(args: string[]): string[] {
|
||||
if (args.length === 0) throw new Error("ssh k3s target exec operation requires a command to exec");
|
||||
const result: string[] = [];
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const arg = args[index] ?? "";
|
||||
if (arg === "--") {
|
||||
if (index === args.length - 1) throw new Error("ssh k3s target exec operation requires a command after --");
|
||||
return [...result, ...args.slice(index)];
|
||||
}
|
||||
if (arg === "--stdin" || arg === "-i" || arg === "--tty" || arg === "-t") {
|
||||
result.push(arg);
|
||||
continue;
|
||||
}
|
||||
if (arg === "--container" || arg === "-c" || arg === "--workdir" || arg === "--cwd") {
|
||||
const value = args[index + 1];
|
||||
if (value === undefined || value.length === 0) throw new Error(`ssh k3s target exec ${arg} requires a value`);
|
||||
result.push(arg, value);
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
return [...result, "--", ...args.slice(index)];
|
||||
}
|
||||
throw new Error("ssh k3s target exec operation requires a command to exec");
|
||||
}
|
||||
|
||||
function buildK3sCommand(providerId: string, args: string[]): string {
|
||||
const action = args[0] ?? "";
|
||||
if (action.length === 0 || action === "--help" || action === "-h" || action === "help") {
|
||||
|
||||
Reference in New Issue
Block a user