feat: add local-only mode for ssh menu
This commit is contained in:
+23
-4
@@ -8,15 +8,17 @@ type Args = {
|
||||
help: boolean
|
||||
configDir: string
|
||||
knownHosts?: string | true
|
||||
localOnly?: string | true
|
||||
}
|
||||
|
||||
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("Options:");
|
||||
console.log(" -h | --help Show this help message");
|
||||
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(" -l | --local-only [user] Include known_hosts only (root if no user provided)");
|
||||
}
|
||||
|
||||
const parseArgs = (argv: string[]): Args => {
|
||||
@@ -57,6 +59,18 @@ const parseArgs = (argv: string[]): Args => {
|
||||
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:
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
@@ -97,7 +111,8 @@ const loadConfig = async () => {
|
||||
port: 22,
|
||||
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("[")) {
|
||||
const hostparts: any = parts[0].split(":");
|
||||
target.host = hostparts[0].substring(1, hostparts[0].length - 1);
|
||||
@@ -146,8 +161,12 @@ const loadConfig = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
if (args.knownHosts) await loadKnownHosts();
|
||||
await loadHosts();
|
||||
if (args.localOnly) {
|
||||
await loadKnownHosts();
|
||||
} else {
|
||||
if (args.knownHosts) await loadKnownHosts();
|
||||
await loadHosts();
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user