UNPKG

@creditkarma/thrift-parser

Version:

A parser for Thrift written in TypeScript

56 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); /** * --rootDir * --fastFail */ function resolveOptions(args) { const len = args.length; let index = 0; const options = { fastFail: false, rootDir: '.', outDir: 'thrift-json', files: [] }; while (index < len) { const next = args[index]; switch (next) { case '--rootDir': options.rootDir = args[(index + 1)]; try { if (fs_1.lstatSync(options.rootDir).isDirectory()) { index += 2; break; } else { throw new Error(`Provided root directory "${options.rootDir}" isn't a directory`); } } catch (e) { throw new Error(`Provided root directory "${options.rootDir}" doesn't exist`); } case '--outDir': options.outDir = args[(index + 1)]; index += 2; break; case '--fastFail': options.fastFail = args[(index + 1)] === 'true'; index += 2; break; default: if (next.startsWith('--')) { throw new Error(`Unknown option provided to generator "${next}"`); } else { // Assume option is a file to parse options.files.push(next); index += 1; } } } return options; } exports.resolveOptions = resolveOptions; //# sourceMappingURL=resolveOptions.js.map