fix: accept equals form for k3s ssh options
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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`);
|
||||
|
||||
Reference in New Issue
Block a user