UNPKG

@kontent-ai/model-generator

Version:

This utility generates strongly-typed models for Delivery JS SDK, Migration toolkit or just general scripting to improve the experience when referencing Kontent.ai related objects.

44 lines 1.68 kB
import chalk from "chalk"; import { match } from "ts-pattern"; import yargs from "yargs"; import { hideBin } from "yargs/helpers"; export async function argumentsFetcherAsync() { const argv = yargs(hideBin(process.argv)); const resolvedArgv = await argv.argv; const getOptionalArgumentValue = (argName) => { return resolvedArgv[argName]?.toString(); }; return { getCliAction() { const command = resolvedArgv._[0]?.toString()?.toLowerCase(); return match(command) .returnType() .with("delivery-sdk", () => "delivery-sdk") .with("migration-toolkit", () => "migration-toolkit") .with("environment", () => "environment") .with("items", () => "items") .otherwise(() => { throw new Error(`Unsupported command '${chalk.red(command)}'`); }); }, getOptionalArgumentValue, getRequiredArgumentValue(argName) { const value = getOptionalArgumentValue(argName); if (!value) { throw new Error(`Missing '${chalk.yellow(argName)}' argument value`); } return value; }, getBooleanArgumentValue(argName, defaultValue) { const value = getOptionalArgumentValue(argName); if (!value) { return defaultValue; } return value.toLowerCase() === "true".toLowerCase(); }, getOptionalArgumentArrayValue(argName) { return getOptionalArgumentValue(argName)?.split(",") ?? []; }, }; } //# sourceMappingURL=args-fetcher.js.map