@odata2ts/odata2ts
Version:
Flexible generator to produce various TypeScript artefacts (from simple model interfaces to complete odata clients) from OData metadata files
57 lines • 2.82 kB
JavaScript
import { Command, Option } from "commander";
import { EmitModes, Modes } from "../OptionModel.js";
function parseMode(value, dummyPrevious) {
switch (value) {
case "models":
return Modes.models;
case "qobjects":
return Modes.qobjects;
case "service":
return Modes.service;
case "all":
return Modes.all;
default:
throw new Error(`Not a valid Mode: ${value}`);
}
}
function parseEmitMode(value, dummyPrevious) {
switch (value) {
case "dts":
return EmitModes.dts;
case "js":
return EmitModes.js;
case "ts":
return EmitModes.ts;
case "js_dts":
return EmitModes.js_dts;
default:
throw new Error(`Not a valid EmitMode: ${value}`);
}
}
export function processCliArgs(argv) {
var _a;
const cli = new Command()
.version("0.3.0")
.description("CLI to generate Typescript Interfaces for models of a given OData service.")
.argument("[services...]", "Run the generation process only for certain services specified in config file", [])
.option("-s, --source <url or metadata.xml>", "Path to metadata file")
.option("-o, --output <path>", "Output location for generated files")
.option("-u, --source-url <sourceUrl>", "URL to the root of the OData service")
.option("-f, --refresh-file", "Download metadata again and overwrite existing file (only applies if sourceUrl is specified)")
.addOption(new Option("-m, --mode <mode>", "What kind of stuff gets generated")
.choices(Object.values(Modes).filter((t) => isNaN(Number(t))))
.argParser(parseMode))
.addOption(new Option("-e, --emit-mode <mode>", "Output TS source files, compiled JS files with/wihthout generated d.ts files")
.choices(Object.values(EmitModes))
.argParser(parseEmitMode))
.option("-p, --prettier", "Format result with prettier (only applies if emitMode=ts)")
.option("-t, --tsconfig <path>", "Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)")
.option("-d, --debug", "Verbose debug infos")
.option("-name, --service-name <serviceName>", "Give the service your own name")
.option("-n, --disable-auto-managed-key", "Don't mark single key props as managed by the server side (not editable)")
.option("-r, --allow-renaming", "Allow that property and entity names may be changed by configured casing")
.parse(argv);
const args = ((_a = cli.args) === null || _a === void 0 ? void 0 : _a.length) ? { services: cli.args } : {};
return Object.assign(Object.assign({}, cli.opts()), args);
}
//# sourceMappingURL=processCliArgs.js.map