UNPKG

@jil/args

Version:

A convention based argument parsing and formatting library, with strict validation checks

25 lines 858 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseInContext = void 0; const errors_1 = require("./errors"); const parse_1 = require("./parse"); /** * Parse a list of command line arguments (typically from `process.argv`) into an arguments * object using a context factory. The factory can customize the parser options based on the * arguments being parsed. */ function parseInContext(argv, context) { let options; // Loop through each arg until we find a context argv.some(arg => { options = context(arg, argv); return !!options; }); // Fail if context not found if (!options) { throw new errors_1.ArgsError('CONTEXT_REQUIRED'); } return (0, parse_1.parse)(argv, options); } exports.parseInContext = parseInContext; //# sourceMappingURL=parseInContext.js.map