From dd1c1dbb25278df7edbfa46b0566465102047da1 Mon Sep 17 00:00:00 2001 From: greysoh Date: Mon, 6 May 2024 16:22:51 -0400 Subject: [PATCH] feature: Adds basic argument parsing for connections. --- lom/src/commands.ts | 9 ++++++++- lom/src/commands/connections.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 lom/src/commands/connections.ts diff --git a/lom/src/commands.ts b/lom/src/commands.ts index ff7487f..c25b751 100644 --- a/lom/src/commands.ts +++ b/lom/src/commands.ts @@ -1,6 +1,8 @@ import type { Axios } from "axios"; -type PrintLine = (...str: string[]) => void; +import { run as connection } from "./commands/connections.js"; + +export type PrintLine = (...str: string[]) => void; type Command = ( args: string[], @@ -34,4 +36,9 @@ export const commands: Commands = [ printf("\x1B[2J\x1B[3J\x1B[H"); }, }, + { + name: "connection", + description: "Various connection related utilities", + run: connection + } ]; diff --git a/lom/src/commands/connections.ts b/lom/src/commands/connections.ts new file mode 100644 index 0000000..6742d92 --- /dev/null +++ b/lom/src/commands/connections.ts @@ -0,0 +1,32 @@ +import { parseArgs } from "node:util"; + +import type { Axios } from "axios"; +import type { PrintLine } from "../commands.js"; + +export async function run( + args: string[], + println: PrintLine, + axios: Axios, + apiKey: string, +) { + const options = parseArgs({ + args, + + strict: false, + allowPositionals: true, + + options: { + tail: { + type: "boolean", + short: "t", + default: false, + }, + }, + }); + + // Special filtering + const values = options.values; + const positionals = options.positionals + .map(i => (!i.startsWith("-") ? i : "")) + .filter(Boolean); +}