UNPKG

clefairy

Version:

Typed CLI argv parser and main function wrapper

21 lines (20 loc) 870 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = run; const clef_parse_1 = require("clef-parse"); const run_main_1 = require("@suchipi/run-main"); const check_options_1 = require("./check-options"); const get_hints_1 = require("./get-hints"); function run(argsObject, mainFunction, runOptions = {}) { const exit = runOptions.exit ?? process.exit.bind(process); const printError = runOptions.printError ?? console.error; return (0, run_main_1.runMain)(() => { const hints = (0, get_hints_1.getHints)(argsObject); const { options, positionalArgs } = (0, clef_parse_1.parseArgv)(runOptions.argv || process.argv.slice(2), hints); (0, check_options_1.checkOptions)(argsObject, options); return mainFunction(options, ...positionalArgs); }, { exit, printError, }); }