UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

43 lines 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeCommand = void 0; exports.tryExecuteRShellCommand = tryExecuteRShellCommand; const ansi_1 = require("../../../util/text/ansi"); /** * Tries to execute the given R shell command. * If not allowed, an error message is printed to the output. */ async function tryExecuteRShellCommand({ output, analyzer, allowRSessionAccess, remainingLine }) { const parserInfo = analyzer.parserInformation(); if (!allowRSessionAccess) { output.stderr(`${output.formatter.format('You are not allowed to execute arbitrary R code.', { style: 1 /* FontStyles.Bold */, color: 1 /* Colors.Red */, effect: ansi_1.ColorEffect.Foreground })} If you want to do so, please restart flowR with the ${output.formatter.format('--r-session-access', { style: 1 /* FontStyles.Bold */ })} flag${parserInfo.name !== 'r-shell' ? '. Additionally, please enable the r-shell engine, e.g., with ' + output.formatter.format('--default-engine r-shell', { style: 1 /* FontStyles.Bold */ }) : ''}. Please be careful of the security implications of this action. When running flowR with npm, you have to use an extra ${output.formatter.format('--', { style: 1 /* FontStyles.Bold */ })} to separate flowR from npm arguments.`); } else if (parserInfo.name === 'r-shell') { await executeRShellCommand(output, analyzer, remainingLine); } else { output.stderr(`Executing arbitrary R code is only possible when using the r-shell engine as the default engine. Enable it using the configuration file or the ${output.formatter.format('--default-engine r-shell', { style: 1 /* FontStyles.Bold */ })} command line option. When running flowR with npm, you have to use an extra ${output.formatter.format('--', { style: 1 /* FontStyles.Bold */ })} to separate flowR from npm arguments.`); } } async function executeRShellCommand(output, analyzer, statement) { try { const result = await analyzer.parserInformation().sendCommandWithOutput(statement, { from: 'both', automaticallyTrimOutput: true }); output.stdout(`${(0, ansi_1.italic)(result.join('\n'), output.formatter)}\n`); } catch (e) { output.stderr(`Error while executing '${statement}': ${e.message}`); } } exports.executeCommand = { description: 'Execute the given code as R code. This requires the `--r-session-access` flag to be set and requires the r-shell engine.', isCodeCommand: false, usageExample: ':execute', aliases: ['e', 'r'], script: false, fn: tryExecuteRShellCommand }; //# sourceMappingURL=repl-execute.js.map