Watch mode support

This commit is contained in:
Endeavorance 2025-03-10 15:22:47 -04:00
parent 2032103412
commit 84b8f1c9d6
8 changed files with 157 additions and 101 deletions

81
src/args.ts Normal file
View file

@ -0,0 +1,81 @@
import { parseArgs } from "node:util";
import { RendererSchema, type Renderer } from "./types";
import { MuseError } from "./errors";
export interface CLIArguments {
inputFilePath: string;
options: {
write: boolean;
check: boolean;
outfile: string;
help: boolean;
minify: boolean;
renderer: Renderer;
watch: boolean;
};
}
export function parseCLIArguments(argv: string[]): CLIArguments {
const { values: options, positionals: args } = parseArgs({
args: argv,
options: {
write: {
short: "w",
type: "boolean",
default: false,
},
check: {
short: "c",
type: "boolean",
default: false,
},
outfile: {
short: "o",
type: "string",
default: "playbill.json",
},
help: {
short: "h",
default: false,
type: "boolean",
},
minify: {
short: "m",
default: false,
type: "boolean",
},
renderer: {
short: "r",
default: "json",
type: "string",
},
watch: {
default: false,
type: "boolean",
},
},
strict: true,
allowPositionals: true,
});
const parsedRenderer = RendererSchema.safeParse(options.renderer);
if (!parsedRenderer.success) {
throw new MuseError(`Invalid renderer: ${parsedRenderer.data}`);
}
return {
inputFilePath: args[0] ?? "./binding.yaml",
options: {
write: options.write,
check: options.check,
outfile: options.outfile,
help: options.help,
minify: options.minify,
renderer: parsedRenderer.data,
watch: options.watch,
},
};
}