@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
70 lines • 4.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCliLongOptionOf = getCliLongOptionOf;
exports.multipleCliOptions = multipleCliOptions;
exports.getConfigOption = getConfigOption;
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");
const config_1 = require("../../config");
const schema_1 = require("../../util/schema");
const doc_files_1 = require("./doc-files");
/**
* Produce the documentation string for a CLI long option
*/
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;
}
/**
* Produce the documentation string for multiple CLI long options
*/
function multipleCliOptions(scriptName, ...options) {
return options.map(o => getCliLongOptionOf(scriptName, o, false, true)).join(' ');
}
/**
* Produce a documentation link for a flowR configuration option (e.g. `solver.sigdb.enabled`).
* The link points at the configuration section of the Interface wiki page and carries the option's
* schema type, description, and any enumerated values as a hover tooltip.
* @param path - The (autocompleted) `.`-separated configuration path.
* @param quote - Whether to render the path as inline code. Default is `true`.
*/
function getConfigOption(path, quote = true) {
const info = (0, schema_1.schemaPathInfo)(config_1.FlowrConfig.Schema, path.split('.'));
let tooltip = `Configuration Option (${info.type ?? 'option'})`;
if (info.description) {
tooltip += `: ${info.description}`;
}
if (info.valids && info.valids.length > 0) {
tooltip += ` (one of ${info.valids.map(v => JSON.stringify(v)).join(', ')})`;
}
const label = quote ? `<code>${(0, doc_escape_1.escapeHTML)(path)}</code>` : (0, doc_escape_1.escapeHTML)(path);
return `<a href="${doc_files_1.FlowrWikiBaseRef}/Interface#configuring-flowr" title=${JSON.stringify((0, doc_escape_1.escapeHTML)(tooltip))}>${label}</a>`;
}
/**
* Produce the documentation string for a REPL command
*/
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