style(cli): apply prettier formatting
Pre-commit hook ran prettier on the prior commit but left the reformats unstaged. Folding them in here so the branch is clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -88,8 +88,7 @@ function parseArgv(argv: string[]): {
|
||||
// Allow `nc list groups` as well as `nc list-groups`. Server rejects
|
||||
// unknowns, so the naive join is safe — at worst the user gets an
|
||||
// unknown-command error.
|
||||
const command =
|
||||
positional.length >= 2 ? `${positional[0]}-${positional[1]}` : positional[0];
|
||||
const command = positional.length >= 2 ? `${positional[0]}-${positional[1]}` : positional[0];
|
||||
|
||||
return { command, args, json };
|
||||
}
|
||||
@@ -124,8 +123,6 @@ function formatTransportError(e: unknown): string {
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
process.stderr.write(
|
||||
`nc: unexpected error: ${err instanceof Error ? err.message : String(err)}\n`,
|
||||
);
|
||||
process.stderr.write(`nc: unexpected error: ${err instanceof Error ? err.message : String(err)}\n`);
|
||||
process.exit(2);
|
||||
});
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
import type { CallerContext, ErrorCode, RequestFrame, ResponseFrame } from './frame.js';
|
||||
import { lookup } from './registry.js';
|
||||
|
||||
export async function dispatch(
|
||||
req: RequestFrame,
|
||||
ctx: CallerContext,
|
||||
): Promise<ResponseFrame> {
|
||||
export async function dispatch(req: RequestFrame, ctx: CallerContext): Promise<ResponseFrame> {
|
||||
const cmd = lookup(req.command);
|
||||
if (!cmd) {
|
||||
return err(req.id, 'unknown-command', `no command "${req.command}"`);
|
||||
|
||||
@@ -41,11 +41,8 @@ function isFlatRecord(x: unknown): x is Record<string, unknown> {
|
||||
function renderTable(rows: Record<string, unknown>[]): string {
|
||||
if (rows.length === 0) return '(no rows)';
|
||||
const cols = Object.keys(rows[0]);
|
||||
const widths = cols.map((c) =>
|
||||
Math.max(c.length, ...rows.map((r) => String(r[c] ?? '').length)),
|
||||
);
|
||||
const fmtRow = (vals: string[]): string =>
|
||||
vals.map((v, i) => v.padEnd(widths[i])).join(' ');
|
||||
const widths = cols.map((c) => Math.max(c.length, ...rows.map((r) => String(r[c] ?? '').length)));
|
||||
const fmtRow = (vals: string[]): string => vals.map((v, i) => v.padEnd(widths[i])).join(' ');
|
||||
const lines = [
|
||||
fmtRow(cols),
|
||||
fmtRow(widths.map((w) => '─'.repeat(w))),
|
||||
|
||||
@@ -23,10 +23,7 @@ export class SocketTransport implements Transport {
|
||||
let buffer = '';
|
||||
let settled = false;
|
||||
|
||||
const settle = (
|
||||
action: 'resolve' | 'reject',
|
||||
valueOrErr: ResponseFrame | Error,
|
||||
): void => {
|
||||
const settle = (action: 'resolve' | 'reject', valueOrErr: ResponseFrame | Error): void => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
try {
|
||||
@@ -51,12 +48,7 @@ export class SocketTransport implements Transport {
|
||||
const frame = JSON.parse(line) as ResponseFrame;
|
||||
settle('resolve', frame);
|
||||
} catch (e) {
|
||||
settle(
|
||||
'reject',
|
||||
new Error(
|
||||
`malformed response from host: ${e instanceof Error ? e.message : String(e)}`,
|
||||
),
|
||||
);
|
||||
settle('reject', new Error(`malformed response from host: ${e instanceof Error ? e.message : String(e)}`));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -107,10 +107,5 @@ function write(conn: net.Socket, frame: ResponseFrame): void {
|
||||
function isRequestFrame(x: unknown): x is RequestFrame {
|
||||
if (!x || typeof x !== 'object') return false;
|
||||
const o = x as Record<string, unknown>;
|
||||
return (
|
||||
typeof o.id === 'string' &&
|
||||
typeof o.command === 'string' &&
|
||||
typeof o.args === 'object' &&
|
||||
o.args !== null
|
||||
);
|
||||
return typeof o.id === 'string' && typeof o.command === 'string' && typeof o.args === 'object' && o.args !== null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user