refactor(cli): dedupe parsePort

This commit is contained in:
Peter Steinberger
2026-02-15 04:02:05 +00:00
parent 6d66fefbbb
commit ab45b409b8
3 changed files with 23 additions and 39 deletions

View File

@@ -8,28 +8,10 @@ import { formatRuntimeStatus } from "../../daemon/runtime-format.js";
import { pickPrimaryLanIPv4 } from "../../gateway/net.js";
import { getResolvedLoggerSettings } from "../../logging.js";
import { formatCliCommand } from "../command-format.js";
import { parsePort } from "../shared/parse-port.js";
export { formatRuntimeStatus };
export function parsePort(raw: unknown): number | null {
if (raw === undefined || raw === null) {
return null;
}
const value =
typeof raw === "string"
? raw
: typeof raw === "number" || typeof raw === "bigint"
? raw.toString()
: null;
if (value === null) {
return null;
}
const parsed = Number.parseInt(value, 10);
if (!Number.isFinite(parsed) || parsed <= 0) {
return null;
}
return parsed;
}
export { parsePort };
export function parsePortFromArgs(programArguments: string[] | undefined): number | null {
if (!programArguments?.length) {