feat: polish nodes cli output
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import type { Command } from "commander";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { formatAge, parsePairingList } from "./format.js";
|
||||
import { runNodesCommand } from "./cli-utils.js";
|
||||
import { getNodesTheme, runNodesCommand } from "./cli-utils.js";
|
||||
import { callGatewayCli, nodesCallOpts, resolveNodeId } from "./rpc.js";
|
||||
import type { NodesRpcOpts } from "./types.js";
|
||||
import { renderTable } from "../../terminal/table.js";
|
||||
|
||||
export function registerNodesPairingCommands(nodes: Command) {
|
||||
nodesCallOpts(
|
||||
@@ -19,16 +20,37 @@ export function registerNodesPairingCommands(nodes: Command) {
|
||||
return;
|
||||
}
|
||||
if (pending.length === 0) {
|
||||
defaultRuntime.log("No pending pairing requests.");
|
||||
const { muted } = getNodesTheme();
|
||||
defaultRuntime.log(muted("No pending pairing requests."));
|
||||
return;
|
||||
}
|
||||
for (const r of pending) {
|
||||
const name = r.displayName || r.nodeId;
|
||||
const repair = r.isRepair ? " (repair)" : "";
|
||||
const ip = r.remoteIp ? ` · ${r.remoteIp}` : "";
|
||||
const age = typeof r.ts === "number" ? ` · ${formatAge(Date.now() - r.ts)} ago` : "";
|
||||
defaultRuntime.log(`- ${r.requestId}: ${name}${repair}${ip}${age}`);
|
||||
}
|
||||
const { heading, warn, muted } = getNodesTheme();
|
||||
const tableWidth = Math.max(60, (process.stdout.columns ?? 120) - 1);
|
||||
const now = Date.now();
|
||||
const rows = pending.map((r) => ({
|
||||
Request: r.requestId,
|
||||
Node: r.displayName?.trim() ? r.displayName.trim() : r.nodeId,
|
||||
IP: r.remoteIp ?? "",
|
||||
Requested:
|
||||
typeof r.ts === "number"
|
||||
? `${formatAge(Math.max(0, now - r.ts))} ago`
|
||||
: muted("unknown"),
|
||||
Repair: r.isRepair ? warn("yes") : "",
|
||||
}));
|
||||
defaultRuntime.log(heading("Pending"));
|
||||
defaultRuntime.log(
|
||||
renderTable({
|
||||
width: tableWidth,
|
||||
columns: [
|
||||
{ key: "Request", header: "Request", minWidth: 8 },
|
||||
{ key: "Node", header: "Node", minWidth: 14, flex: true },
|
||||
{ key: "IP", header: "IP", minWidth: 10 },
|
||||
{ key: "Requested", header: "Requested", minWidth: 12 },
|
||||
{ key: "Repair", header: "Repair", minWidth: 6 },
|
||||
],
|
||||
rows,
|
||||
}).trimEnd(),
|
||||
);
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -86,7 +108,8 @@ export function registerNodesPairingCommands(nodes: Command) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(`node rename ok: ${nodeId} -> ${name}`);
|
||||
const { ok } = getNodesTheme();
|
||||
defaultRuntime.log(ok(`node rename ok: ${nodeId} -> ${name}`));
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user