@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
38 lines • 2.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCliLongOptionOf = getCliLongOptionOf;
exports.multipleCliOptions = multipleCliOptions;
exports.getReplCommand = getReplCommand;
/** Automatically provides hover over with the documentation for these! */
const scripts_info_1 = require("../../cli/common/scripts-info");
const assert_1 = require("../../util/assert");
const html_hover_over_1 = require("../../util/html-hover-over");
const flowr_main_options_1 = require("../../cli/flowr-main-options");
const repl_commands_1 = require("../../cli/repl/commands/repl-commands");
const doc_escape_1 = require("./doc-escape");
function getCliLongOptionOf(scriptName, optionName, withAlias = false, quote = true) {
const script = scriptName === 'flowr' ? flowr_main_options_1.flowrMainOptionDefinitions : scripts_info_1.scripts[scriptName].options;
(0, assert_1.guard)(script !== undefined, () => `Unknown script ${scriptName}, pick one of ${JSON.stringify(Object.keys(scripts_info_1.scripts))}.`);
const option = script.find(({ name }) => name === optionName);
(0, assert_1.guard)(option !== undefined, () => `Unknown option ${optionName}, pick one of ${JSON.stringify(script.map(o => o.name))}.`);
const char = quote ? '`' : '';
const description = (0, doc_escape_1.escapeHTML)(option.description);
const alias = withAlias && option.alias ? ' (alias:' + (0, html_hover_over_1.textWithTooltip)(`${char}-${option.alias}${char}`, description) + ')' : '';
const ligatureBreaker = quote ? '' : '<span/>';
// span ensures split even with ligatures
return (0, html_hover_over_1.textWithTooltip)(`${char}-${ligatureBreaker}-${optionName}${char}`, 'Description (Command Line Argument): ' + description) + alias;
}
function multipleCliOptions(scriptName, ...options) {
return options.map(o => getCliLongOptionOf(scriptName, o, false, true)).join(' ');
}
function getReplCommand(commandName, quote = true, showStar = false) {
const availableNames = (0, repl_commands_1.getReplCommands)();
const commands = availableNames[commandName];
(0, assert_1.guard)(commands !== undefined, () => `Unknown command ${commandName}, pick one of ${JSON.stringify(Object.keys(availableNames))}.`);
const char = quote ? '`' : '';
const aliases = commands.aliases.length > 0 ? ' (aliases: ' + commands.aliases.map(a => `:${a}`).join(', ') + ')' : '';
const starredComment = commandName.endsWith('*') ? ', starred version' : '';
const baseDescription = commandName.endsWith('*') ? '; Base Command: ' + availableNames[commandName.slice(0, -1)].description : '';
return (0, html_hover_over_1.textWithTooltip)(`${char}:${commandName}${showStar ? '[*]' : ''}${char}`, `Description (Repl Command${starredComment}): ` + commands.description + baseDescription + aliases);
}
//# sourceMappingURL=doc-cli-option.js.map