UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

61 lines 2.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.helpForOptions = helpForOptions; exports.processCommandLineArgs = processCommandLineArgs; /** * The goal of this module is simply to streamline the creation of new scripts. * @module */ const scripts_info_1 = require("./scripts-info"); const command_line_usage_1 = __importDefault(require("command-line-usage")); const command_line_args_1 = __importDefault(require("command-line-args")); const ansi_1 = require("../../util/text/ansi"); const log_1 = require("../../util/log"); /** * Automatically generates a uniform help from a given script (see {@link scripts}). * Additionally, you can pass usage examples that may make use of the formatting instructions `{italic x}` and `{bold x}`. */ function helpForOptions(script, content) { return (0, command_line_usage_1.default)([ { header: scripts_info_1.scripts[script].description, content: content.subtitle }, { header: 'Synopsis', content: content.examples.map(e => `$ ${scripts_info_1.scripts[script].toolName} ${e}`) }, { header: 'Options', optionList: scripts_info_1.scripts[script].options } ]); } /** * Processes the command line arguments for a given script. */ function processCommandLineArgs(script, requireAdditionally, help) { const options = (0, command_line_args_1.default)(scripts_info_1.scripts[script].options); if (options.help) { console.log(helpForOptions(script, help)); process.exit(0); } else if (requireAdditionally.length > 0) { const keys = new Set(Object.keys(options)); const missing = requireAdditionally.filter(k => !keys.has(k) || options[k] === undefined); if (missing.length > 0) { console.error((0, ansi_1.italic)(`Missing required arguments: ${missing.join(', ')}. Showing help.`)); console.log(helpForOptions(script, help)); process.exit(0); } } log_1.log.updateSettings(l => l.settings.minLevel = options.verbose ? 1 /* LogLevel.Trace */ : 5 /* LogLevel.Error */); if (options.verbose) { log_1.log.info(`running with (debugging) options, ${JSON.stringify(options)}`); } return options; } //# sourceMappingURL=script.js.map