| 306 | } |
| 307 | |
| 308 | int 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 | |
| 349 | incomplete: |
| 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 << " .. "; |
nothing calls this directly
no test coverage detected