feat: add local-only mode for ssh menu

This commit is contained in:
2026-06-06 01:54:37 +02:00
parent 519f1c3bae
commit 1e55168116
+23 -4
View File
@@ -8,15 +8,17 @@ type Args = {
help: boolean help: boolean
configDir: string configDir: string
knownHosts?: string | true knownHosts?: string | true
localOnly?: string | true
} }
const usage = () => { const usage = () => {
console.log("Usage: sshm [--config-dir DIR] [-k [user]]"); console.log("Usage: sshm [--config-dir DIR] [ [-k [user]] || [-l [user]] ]");
console.log(""); console.log("");
console.log("Options:"); console.log("Options:");
console.log(" -h | --help Show this help message"); console.log(" -h | --help Show this help message");
console.log(" -c | --config-dir DIR Use a custom config directory"); console.log(" -c | --config-dir DIR Use a custom config directory");
console.log(" -k | --known-hosts [user] Include known_hosts (root if no user provided)"); console.log(" -k | --known-hosts [user] Include known_hosts (root if no user provided)");
console.log(" -l | --local-only [user] Include known_hosts only (root if no user provided)");
} }
const parseArgs = (argv: string[]): Args => { const parseArgs = (argv: string[]): Args => {
@@ -57,6 +59,18 @@ const parseArgs = (argv: string[]): Args => {
break; break;
} }
case "-l":
case "--local-only": {
const next = argv[i + 1];
if (next && !next.startsWith("-")) {
args.localOnly = next;
i++;
} else {
args.localOnly = true;
}
break;
}
default: default:
throw new Error(`Unknown argument: ${arg}`); throw new Error(`Unknown argument: ${arg}`);
} }
@@ -97,7 +111,8 @@ const loadConfig = async () => {
port: 22, port: 22,
name: '', name: '',
} }
if (args.knownHosts != true) target.user = args.knownHosts as string; if (args.knownHosts && args.knownHosts != true) target.user = args.knownHosts as string;
if (args.localOnly && args.localOnly != true) target.user = args.localOnly as string;
if (parts[0].startsWith("[")) { if (parts[0].startsWith("[")) {
const hostparts: any = parts[0].split(":"); const hostparts: any = parts[0].split(":");
target.host = hostparts[0].substring(1, hostparts[0].length - 1); target.host = hostparts[0].substring(1, hostparts[0].length - 1);
@@ -146,8 +161,12 @@ const loadConfig = async () => {
} }
} }
if (args.knownHosts) await loadKnownHosts(); if (args.localOnly) {
await loadHosts(); await loadKnownHosts();
} else {
if (args.knownHosts) await loadKnownHosts();
await loadHosts();
}
return config; return config;
} }