feature: Adds basic argument parsing for connections.

This commit is contained in:
greysoh 2024-05-06 16:22:51 -04:00
parent 7f34ddd6c5
commit dd1c1dbb25
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
2 changed files with 40 additions and 1 deletions

View file

@ -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
}
];

View file

@ -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);
}