vault-link/frontend/deterministic-tests/src/parse-args.ts
Andras Schmelczer 0e3132f96c
Some checks are pending
Check / build (push) Waiting to run
E2E tests / build (push) Waiting to run
Publish CLI / publish-docker (push) Waiting to run
Publish server Docker image / publish-docker (push) Waiting to run
Add deterministic-tests (#190)
Reviewed-on: https://home.schmelczer.dev/git/git/andras/vault-link/pulls/190
Co-authored-by: Andras Schmelczer <andras@schmelczer.dev>
Co-committed-by: Andras Schmelczer <andras@schmelczer.dev>
2026-05-09 10:15:21 +01:00

43 lines
1.2 KiB
TypeScript

import * as os from "node:os";
import { Command, InvalidArgumentError } from "commander";
export interface CliArgs {
filter: string | undefined;
concurrency: number;
}
function parsePositiveInt(value: string): number {
const n = parseInt(value, 10);
if (isNaN(n) || n <= 0) {
throw new InvalidArgumentError("must be a positive integer");
}
return n;
}
export function parseArgs(argv: string[]): CliArgs {
const program = new Command();
program
.name("deterministic-tests")
.description("Scripted multi-client sync tests against a real server")
.option(
"-f, --filter <substring>",
"Run only tests whose name contains this substring"
)
.option(
"-j, --concurrency <number>",
"Number of tests to run in parallel",
parsePositiveInt,
os.cpus().length
);
program.parse(argv);
/* eslint-disable @typescript-eslint/no-unsafe-type-assertion */
const opts = program.opts();
const filter = opts.filter as string | undefined;
const concurrency = opts.concurrency as number;
/* eslint-enable @typescript-eslint/no-unsafe-type-assertion */
return { filter, concurrency };
}