feature: Adds basic argument parsing for connections.
This commit is contained in:
parent
7f34ddd6c5
commit
dd1c1dbb25
2 changed files with 40 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
];
|
||||
|
|
32
lom/src/commands/connections.ts
Normal file
32
lom/src/commands/connections.ts
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue