UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

84 lines (80 loc) 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.printReplHelpAsMarkdownTable = printReplHelpAsMarkdownTable; exports.documentReplSession = documentReplSession; const repl_commands_1 = require("../../cli/repl/commands/repl-commands"); const doc_cli_option_1 = require("./doc-cli-option"); const html_hover_over_1 = require("../../util/html-hover-over"); const core_1 = require("../../cli/repl/core"); const ansi_1 = require("../../util/text/ansi"); const doc_docker_1 = require("./doc-docker"); const prompt_1 = require("../../cli/repl/prompt"); const doc_code_1 = require("./doc-code"); const print_version_1 = require("../../cli/repl/print-version"); const config_1 = require("../../config"); function printHelpForScript(script, starredVersion) { let base = `| **${(0, doc_cli_option_1.getReplCommand)(script[0], false, starredVersion !== undefined)}** | ${script[1].description}`; if (starredVersion) { base += ` (star: ${starredVersion.description})`; } if (script[1].aliases.length === 0) { return base; } const aliases = script[1].aliases; return `${base} (alias${aliases.length > 1 ? 'es' : ''}: ${aliases.map(a => '**:' + (0, html_hover_over_1.textWithTooltip)(a, `Alias of ':${script[0]}'. ${script[1].description}`) + '**').join(', ')}) |`; } function printReplHelpAsMarkdownTable() { const scriptHelp = []; const cmds = (0, repl_commands_1.getReplCommands)(); for (const c of Object.entries(cmds)) { if (c[1].script || c[0].endsWith('*')) { continue; } const starred = cmds[c[0] + '*']; scriptHelp.push(printHelpForScript(c, starred)); } return ` | Command | Description | | ------- | ----------- | ${scriptHelp.sort().join('\n')} `; } async function documentReplSession(parser, commands, options) { const collect = []; for (const command of commands) { const entry = { command, lines: [] }; const collectingOutput = { formatter: ansi_1.voidFormatter, stdout(msg) { entry.lines.push(msg); }, stderr(msg) { entry.lines.push(msg); } }; await (0, core_1.replProcessAnswer)(config_1.defaultConfigOptions, collectingOutput, command.command, parser, options?.allowRSessionAccess ?? false); collect.push(entry); } let result = ''; let cache = options?.hideEntry ? '' : `$ docker run -it --rm ${doc_docker_1.DockerName} ${options?.args ? options?.args + ' ' : ''}# or npm run flowr ${options?.args ? '-- ' + options?.args : ''}\n`; if (!options?.hideEntry) { cache += await (0, print_version_1.versionReplString)(parser) + '\n'; } for (const { command, lines } of collect) { if (lines.length === 0) { cache += prompt_1.rawPrompt + ' ' + command.command + '\n'; continue; } result += ` ${(0, doc_code_1.codeBlock)('shell', cache + prompt_1.rawPrompt + ' ' + command.command)} <details${options?.openOutput ? ' open' : ''}> <summary style='color:gray'>Output</summary> ${(0, doc_code_1.codeBlock)('text', lines.join('\n'))} ${command.description} </details> `; cache = ''; } return result; } //# sourceMappingURL=doc-repl.js.map