e41ebe61ec
- Added SSH host management feature with `ssh` CLI command and `/ssh` slash command for add, list, and remove operations. - Added SSH configuration support at project (.omp/ssh.json) and user (~/.omp/agent/ssh.json) scopes with host discovery from project files. - Added SSH host configuration flags: --host, --user, --port, --key, --desc, --compat, and --scope for flexible host setup. - Removed automatic line relocation on stale hash references; now fails with error instead.
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
/**
|
|
* Manage SSH host configurations.
|
|
*/
|
|
import { Args, Command, Flags } from "@oh-my-pi/pi-utils/cli";
|
|
import { runSSHCommand, type SSHAction, type SSHCommandArgs } from "../cli/ssh-cli";
|
|
import { initTheme } from "../modes/theme/theme";
|
|
|
|
const ACTIONS: SSHAction[] = ["add", "remove", "list"];
|
|
|
|
export default class SSH extends Command {
|
|
static description = "Manage SSH host configurations";
|
|
|
|
static args = {
|
|
action: Args.string({
|
|
description: "SSH action",
|
|
required: false,
|
|
options: ACTIONS,
|
|
}),
|
|
targets: Args.string({
|
|
description: "Host name or arguments",
|
|
required: false,
|
|
multiple: true,
|
|
}),
|
|
};
|
|
|
|
static flags = {
|
|
json: Flags.boolean({ description: "Output JSON" }),
|
|
host: Flags.string({ description: "Host address" }),
|
|
user: Flags.string({ description: "Username" }),
|
|
port: Flags.string({ description: "Port number" }),
|
|
key: Flags.string({ description: "Identity key path" }),
|
|
desc: Flags.string({ description: "Host description" }),
|
|
compat: Flags.boolean({ description: "Enable compatibility mode" }),
|
|
scope: Flags.string({ description: "Config scope (project|user)", options: ["project", "user"] }),
|
|
};
|
|
|
|
async run(): Promise<void> {
|
|
const { args, flags } = await this.parse(SSH);
|
|
const action = (args.action ?? "list") as SSHAction;
|
|
const targets = Array.isArray(args.targets) ? args.targets : args.targets ? [args.targets] : [];
|
|
|
|
const cmd: SSHCommandArgs = {
|
|
action,
|
|
args: targets,
|
|
flags: {
|
|
json: flags.json,
|
|
host: flags.host,
|
|
user: flags.user,
|
|
port: flags.port,
|
|
key: flags.key,
|
|
desc: flags.desc,
|
|
compat: flags.compat,
|
|
scope: flags.scope as "project" | "user" | undefined,
|
|
},
|
|
};
|
|
|
|
await initTheme();
|
|
await runSSHCommand(cmd);
|
|
}
|
|
}
|