feat (cli): add account selector for pairing commands

This commit is contained in:
Vignesh Natarajan
2026-02-15 19:09:14 -08:00
parent 6957354d48
commit 6cf7c02d4a
2 changed files with 60 additions and 5 deletions

View File

@@ -94,6 +94,20 @@ describe("pairing cli", () => {
expect(listChannelPairingRequests).toHaveBeenCalledWith("telegram");
});
it("forwards --account for list", async () => {
const { registerPairingCli } = await import("./pairing-cli.js");
listChannelPairingRequests.mockResolvedValueOnce([]);
const program = new Command();
program.name("test");
registerPairingCli(program);
await program.parseAsync(["pairing", "list", "--channel", "telegram", "--account", "yy"], {
from: "user",
});
expect(listChannelPairingRequests).toHaveBeenCalledWith("telegram", process.env, "yy");
});
it("normalizes channel aliases", async () => {
const { registerPairingCli } = await import("./pairing-cli.js");
listChannelPairingRequests.mockResolvedValueOnce([]);
@@ -170,4 +184,33 @@ describe("pairing cli", () => {
});
expect(log).toHaveBeenCalledWith(expect.stringContaining("Approved"));
});
it("forwards --account for approve", async () => {
const { registerPairingCli } = await import("./pairing-cli.js");
approveChannelPairingCode.mockResolvedValueOnce({
id: "123",
entry: {
id: "123",
code: "ABCDEFGH",
createdAt: "2026-01-08T00:00:00Z",
lastSeenAt: "2026-01-08T00:00:00Z",
},
});
const program = new Command();
program.name("test");
registerPairingCli(program);
await program.parseAsync(
["pairing", "approve", "--channel", "telegram", "--account", "yy", "ABCDEFGH"],
{
from: "user",
},
);
expect(approveChannelPairingCode).toHaveBeenCalledWith({
channel: "telegram",
code: "ABCDEFGH",
accountId: "yy",
});
});
});

View File

@@ -64,6 +64,7 @@ export function registerPairingCli(program: Command) {
.command("list")
.description("List pending pairing requests")
.option("--channel <channel>", `Channel (${channels.join(", ")})`)
.option("--account <accountId>", "Account id (for multi-account channels)")
.argument("[channel]", `Channel (${channels.join(", ")})`)
.option("--json", "Print JSON", false)
.action(async (channelArg, opts) => {
@@ -74,7 +75,10 @@ export function registerPairingCli(program: Command) {
);
}
const channel = parseChannel(channelRaw, channels);
const requests = await listChannelPairingRequests(channel);
const accountId = String(opts.account ?? "").trim();
const requests = accountId
? await listChannelPairingRequests(channel, process.env, accountId)
: await listChannelPairingRequests(channel);
if (opts.json) {
defaultRuntime.log(JSON.stringify({ channel, requests }, null, 2));
return;
@@ -111,6 +115,7 @@ export function registerPairingCli(program: Command) {
.command("approve")
.description("Approve a pairing code and allow that sender")
.option("--channel <channel>", `Channel (${channels.join(", ")})`)
.option("--account <accountId>", "Account id (for multi-account channels)")
.argument("<codeOrChannel>", "Pairing code (or channel when using 2 args)")
.argument("[code]", "Pairing code (when channel is passed as the 1st arg)")
.option("--notify", "Notify the requester on the same channel", false)
@@ -128,10 +133,17 @@ export function registerPairingCli(program: Command) {
);
}
const channel = parseChannel(channelRaw, channels);
const approved = await approveChannelPairingCode({
channel,
code: String(resolvedCode),
});
const accountId = String(opts.account ?? "").trim();
const approved = accountId
? await approveChannelPairingCode({
channel,
code: String(resolvedCode),
accountId,
})
: await approveChannelPairingCode({
channel,
code: String(resolvedCode),
});
if (!approved) {
throw new Error(`No pending pairing request found for code: ${String(resolvedCode)}`);
}