MCPcopy Create free account
hub / github.com/Icinga/icinga2 / RunScriptConsole

Method RunScriptConsole

lib/cli/consolecommand.cpp:308–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& connectAddr, const String& session,
309 const String& commandOnce, const String& commandOnceFileName, bool syntaxOnly)
310{
311 std::map<String, String> lines;
312 int next_line = 1;
313
314#ifdef HAVE_EDITLINE
315 String homeEnv = Utility::GetFromEnvironment("HOME");
316
317 String historyPath;
318 std::fstream historyfp;
319
320 if (!homeEnv.IsEmpty()) {
321 historyPath = String(homeEnv) + "/.icinga2_history";
322
323 historyfp.open(historyPath.CStr(), std::fstream::in);
324
325 String line;
326 while (std::getline(historyfp, line.GetData()))
327 add_history(line.CStr());
328
329 historyfp.close();
330 }
331#endif /* HAVE_EDITLINE */
332
333 l_ScriptFrame = &scriptFrame;
334 l_Session = session;
335
336 while (std::cin.good()) {
337 String fileName;
338
339 if (commandOnceFileName.IsEmpty())
340 fileName = "<" + Convert::ToString(next_line) + ">";
341 else
342 fileName = commandOnceFileName;
343
344 next_line++;
345
346 bool continuation = false;
347 std::string command;
348
349incomplete:
350 std::string line;
351
352 if (commandOnce.IsEmpty()) {
353#ifdef HAVE_EDITLINE
354 std::ostringstream promptbuf;
355 std::ostream& os = promptbuf;
356#else /* HAVE_EDITLINE */
357 std::ostream& os = std::cout;
358#endif /* HAVE_EDITLINE */
359
360 os << fileName;
361
362 if (!continuation)
363 os << " => ";
364 else
365 os << " .. ";

Callers

nothing calls this directly

Calls 15

LogClass · 0.85
ConsoleColorTagClass · 0.85
CStrMethod · 0.80
closeMethod · 0.80
EvaluateMethod · 0.80
findMethod · 0.80
SplitMethod · 0.80
StringClass · 0.50
IsEmptyMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected