Organize into folders
This commit is contained in:
parent
84b8f1c9d6
commit
2e0d4b45ea
12 changed files with 121 additions and 64 deletions
81
src/args.ts
81
src/args.ts
|
@ -1,81 +0,0 @@
|
|||
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,
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue