Line data Source code
1 : /*! 2 : * \file esys/repo/exe/cmd.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2020-2023 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/exe/cmd.h" 20 : #include "esys/repo/filesystem.h" 21 : #include "esys/repo/configfolder.h" 22 : #include "esys/repo/gitmngr.h" 23 : #include "esys/repo/manifest/capture.h" 24 : #include "esys/repo/manifest/repository.h" 25 : #include "esys/repo/manifest/multifilexml.h" 26 : 27 : #include <esys/log/consolelockguard.h> 28 : 29 : #include <boost/filesystem.hpp> 30 : 31 : #include <iomanip> 32 : #include <iostream> 33 : #include <sstream> 34 : 35 : namespace esys::repo::exe 36 : { 37 : 38 306 : Cmd::Cmd(const std::string &name) 39 : : log::User() 40 306 : , m_name(name) 41 : { 42 306 : } 43 : 44 652 : Cmd::~Cmd() = default; 45 : 46 166 : const std::string &Cmd::get_name() const 47 : { 48 166 : return m_name; 49 : } 50 : 51 39 : void Cmd::set_job_count(int job_count) 52 : { 53 39 : m_job_count = job_count; 54 39 : } 55 : 56 30 : int Cmd::get_job_count() const 57 : { 58 30 : return m_job_count; 59 : } 60 : 61 0 : void Cmd::set_user_config(std::shared_ptr<UserConfig> user_config) 62 : { 63 0 : m_user_config = user_config; 64 0 : } 65 : 66 0 : std::shared_ptr<UserConfig> Cmd::get_user_config() const 67 : { 68 0 : return m_user_config; 69 : } 70 : 71 71 : void Cmd::set_user_folder(std::shared_ptr<UserFolder> user_folder) 72 : { 73 71 : m_user_folder = user_folder; 74 71 : } 75 : 76 170 : std::shared_ptr<UserFolder> Cmd::get_user_folder() const 77 : { 78 170 : return m_user_folder; 79 : } 80 : 81 85 : Result Cmd::load_or_create_user_config() 82 : { 83 170 : if (get_user_folder() == nullptr) set_user_folder(std::make_shared<UserFolder>()); 84 : 85 85 : auto user_folder = get_user_folder(); 86 85 : auto result = user_folder->read(); 87 85 : if (result.error()) 88 : { 89 0 : if (!boost::filesystem::exists(user_folder->get_user_config_file_path())) 90 : { 91 0 : result = user_folder->create(true); 92 0 : if (result.error()) 93 0 : warn("User config file doesn't exit and couldn't create it."); 94 : else 95 0 : info("User config file created."); 96 : } 97 : else 98 0 : warn("Couldn't read the user config file."); 99 : } 100 : else 101 170 : info("User config file loaded successfully."); 102 : 103 85 : return ESYSREPO_RESULT(ResultCode::OK); 104 170 : } 105 : 106 85 : Result Cmd::run() 107 : { 108 85 : m_start_time = std::chrono::steady_clock::now(); 109 : 110 85 : if (get_print_cmd_name_by_base()) print_cmd_name(); 111 : 112 170 : if (get_git() == nullptr) set_git(GitMngr::new_ptr()); 113 340 : if (get_logger_if() != nullptr) get_git()->set_logger_if(get_logger_if()); 114 : 115 85 : Result result = load_or_create_user_config(); 116 85 : if (result.error()) 117 : { 118 0 : error("Some features will not work because the user config file issues."); 119 : } 120 85 : result = impl_run(); 121 : 122 85 : auto stop_time = std::chrono::steady_clock::now(); 123 85 : auto d_milli = std::chrono::duration_cast<std::chrono::milliseconds>(stop_time - m_start_time).count(); 124 : 125 85 : if (get_print_result_summary()) 126 : { 127 83 : std::ostringstream oss; 128 83 : std::string msg; 129 : 130 83 : msg = get_name(); 131 83 : oss << " elapsed time (s): " << (d_milli / THOUSAND) << "." << (d_milli % THOUSAND); 132 83 : if (result.ok()) 133 : { 134 80 : msg += " done.\n"; 135 160 : msg += oss.str(); 136 80 : info(msg); 137 : } 138 : else 139 : { 140 3 : msg += " failed.\n"; 141 6 : msg += oss.str(); 142 3 : error(msg); 143 : } 144 83 : } 145 255 : return ESYSREPO_RESULT(result); 146 85 : } 147 : 148 64 : void Cmd::set_manifest(std::shared_ptr<Manifest> manifest) 149 : { 150 64 : m_manifest = manifest; 151 64 : } 152 : 153 642 : std::shared_ptr<Manifest> Cmd::get_manifest() const 154 : { 155 642 : return m_manifest; 156 : } 157 : 158 78 : void Cmd::set_git(std::shared_ptr<GitBase> git) 159 : { 160 78 : m_git = git; 161 78 : } 162 : 163 521 : std::shared_ptr<GitBase> Cmd::get_git() const 164 : { 165 521 : return m_git; 166 : } 167 : 168 217 : void Cmd::set_workspace_path(const std::string &workspace_path) 169 : { 170 217 : m_workspace_path = workspace_path; 171 217 : } 172 : 173 383 : const std::string &Cmd::get_workspace_path() const 174 : { 175 859 : if ((get_config_folder() != nullptr) && (!get_config_folder()->get_workspace_path().empty())) 176 184 : return get_config_folder()->get_workspace_path(); 177 291 : return m_workspace_path; 178 : } 179 : 180 36 : std::string Cmd::find_workspace_path(const std::string &path) 181 : { 182 36 : boost::filesystem::path cur_path; 183 : 184 36 : if (!path.empty()) 185 36 : cur_path = path; 186 : else 187 0 : cur_path = boost::filesystem::current_path(); 188 : 189 36 : while (!cur_path.empty()) 190 : { 191 36 : if (ConfigFolder::is_config_folder(cur_path.string())) return cur_path.string(); 192 0 : cur_path = cur_path.parent_path(); 193 : } 194 : 195 0 : return ""; 196 36 : } 197 : 198 0 : std::string Cmd::find_git_repo_path(const std::string &path) 199 : { 200 0 : boost::filesystem::path cur_path; 201 : 202 0 : if (!path.empty()) 203 0 : cur_path = path; 204 : else 205 0 : cur_path = boost::filesystem::current_path(); 206 : 207 0 : while (!cur_path.empty()) 208 : { 209 0 : if (GitBase::is_repo(cur_path.string())) return cur_path.string(); 210 0 : cur_path = cur_path.parent_path(); 211 : } 212 : 213 0 : return ""; 214 0 : } 215 : 216 115 : void Cmd::set_debug(bool debug) 217 : { 218 115 : m_debug = debug; 219 115 : } 220 : 221 29 : bool Cmd::get_debug() const 222 : { 223 29 : return m_debug; 224 : } 225 : 226 75 : void Cmd::set_folder(const std::string &folder) 227 : { 228 75 : m_folder = folder; 229 : 230 : /*boost::filesystem::path path = Cmd::find_workspace_path(folder); 231 : if (path.empty()) return -1; 232 : 233 : set_workspace_path(path.string());*/ 234 75 : } 235 : 236 166 : const std::string &Cmd::get_folder() const 237 : { 238 166 : return m_folder; 239 : } 240 : 241 13 : bool Cmd::is_git_root_folder(const std::string &path) 242 : { 243 13 : boost::filesystem::path folder_path = path; 244 : 245 13 : folder_path /= ".git"; 246 13 : return boost::filesystem::exists(folder_path); 247 13 : } 248 : 249 13 : std::string Cmd::find_git_root_path(const std::string &folder_path) 250 : { 251 13 : boost::filesystem::path cur_path = folder_path; 252 : 253 13 : while (!cur_path.empty()) 254 : { 255 13 : if (is_git_root_folder(cur_path.string())) 256 : { 257 13 : return cur_path.string(); 258 : } 259 0 : cur_path = cur_path.parent_path(); 260 : } 261 0 : return ""; 262 13 : } 263 : 264 1 : Result Cmd::load_capture(std::shared_ptr<manifest::Capture> capture, const std::string ¬e_text) 265 : { 266 1 : manifest::MultiFileXML file_xml; 267 1 : std::istringstream iss; 268 : 269 1 : iss.str(note_text); 270 2 : file_xml.set_capture(capture); 271 : 272 1 : auto result = file_xml.read(iss); 273 1 : if (result.error()) return ESYSREPO_RESULT(result); 274 1 : return ESYSREPO_RESULT(ResultCode::OK); 275 1 : } 276 : 277 0 : void Cmd::print_capture(std::ostream &os, std::shared_ptr<manifest::Capture> capture) 278 : { 279 0 : for (auto repo : capture->get_items()) 280 : { 281 0 : os << std::endl; 282 0 : os << std::setw(20) << std::left << repo->get_path() << repo->get_revision(); 283 0 : } 284 0 : } 285 : 286 0 : Result Cmd::print_esysrepo_note(std::ostream &os, const std::string ¬e_text) 287 : { 288 0 : auto capture = std::make_shared<manifest::Capture>(); 289 0 : auto result = load_capture(capture, note_text); 290 0 : if (result.error()) ESYSREPO_RESULT(result); 291 : 292 0 : print_capture(os, capture); 293 0 : return ESYSREPO_RESULT(ResultCode::OK); 294 0 : } 295 : 296 93 : void Cmd::set_sub_args(const std::vector<std::string> &sub_args) 297 : { 298 93 : m_sub_args = sub_args; 299 93 : } 300 : 301 66 : const std::vector<std::string> &Cmd::get_sub_args() const 302 : { 303 66 : return m_sub_args; 304 : } 305 : 306 75 : void Cmd::set_time(bool time) 307 : { 308 75 : m_time = time; 309 75 : } 310 : 311 0 : bool Cmd::get_time() const 312 : { 313 0 : return m_time; 314 : } 315 : 316 75 : void Cmd::set_delta_time(bool delta_time) 317 : { 318 75 : m_delta_time = delta_time; 319 75 : } 320 : 321 0 : bool Cmd::get_delta_time() const 322 : { 323 0 : return m_delta_time; 324 : } 325 : 326 3 : void Cmd::set_groups(const std::vector<std::string> &groups) 327 : { 328 3 : m_groups = groups; 329 3 : } 330 : 331 24 : const std::vector<std::string> &Cmd::get_groups() const 332 : { 333 24 : return m_groups; 334 : } 335 : 336 236 : void Cmd::set_cli_cmd(cli::Cmd *cli_cmd) 337 : { 338 236 : m_cli_cmd = cli_cmd; 339 236 : } 340 : 341 0 : cli::Cmd *Cmd::get_cli_cmd() 342 : { 343 0 : return m_cli_cmd; 344 : } 345 : 346 236 : void Cmd::set_app_base(cli::AppBase *app_base) 347 : { 348 236 : m_app_base = app_base; 349 236 : } 350 : 351 3 : cli::AppBase *Cmd::get_app_base() 352 : { 353 3 : return m_app_base; 354 : } 355 : 356 0 : int Cmd::process_sub_args_as_git_repo_path(const std::string &input_path) 357 : { 358 0 : if (input_path.empty()) return 0; 359 : 360 0 : boost::filesystem::path the_input_path = input_path; 361 0 : if (the_input_path == ".") the_input_path = boost::filesystem::current_path(); 362 : 363 0 : boost::filesystem::path git_repo = Cmd::find_git_repo_path(the_input_path.string()); 364 0 : boost::filesystem::path workspace_path = get_workspace_path(); 365 : 366 0 : if (workspace_path.empty()) 367 : { 368 0 : workspace_path = Cmd::find_workspace_path(the_input_path.string()); 369 : 370 0 : if (workspace_path.empty()) 371 : { 372 0 : error("Requires ESysRepo to be installed first."); 373 0 : return -1; 374 : } 375 : else 376 0 : set_workspace_path(workspace_path.string()); 377 : } 378 : 379 0 : if (git_repo.empty()) 380 : { 381 : // Folder may not be cloned yet, or the argument is a manifest path. 382 0 : auto repo = get_manifest()->find_repo_by_path(the_input_path.generic_string()); 383 0 : if (repo == nullptr) 384 : { 385 0 : error("The given path doesn't exists : " + the_input_path.string()); 386 0 : return -1; 387 : } 388 0 : m_input_rel_git_repo_paths.push_back(repo->get_path()); 389 : return 0; 390 0 : } 391 : 392 0 : if (!boost::filesystem::exists(the_input_path)) 393 : { 394 : // The input path doesn't exist 395 : // Couldn't it be the relative path of a git repo in the manifest? 396 0 : auto repo = get_manifest()->find_repo_by_path(the_input_path.generic_string()); 397 0 : if (repo == nullptr) 398 : { 399 0 : error("The given path doesn't exists : " + the_input_path.string()); 400 0 : return -1; 401 : } 402 : 403 : // This was indeed the relative path of a git repo in the manifest 404 0 : git_repo = repo->get_path(); 405 0 : } 406 : else 407 : { 408 : // We need to find which repo this is related too 409 0 : boost::filesystem::path git_rel_path = boost::filesystem::relative(git_repo, workspace_path); 410 : 411 0 : if (git_rel_path.empty()) 412 : { 413 0 : error("The following git repo doesn't seem to be known by ESysRepo: " + git_repo.string()); 414 0 : return -1; 415 : } 416 0 : git_repo = git_rel_path; 417 0 : } 418 0 : m_input_rel_git_repo_paths.push_back(git_repo.generic_path().string()); 419 0 : return 0; 420 0 : } 421 : 422 3 : Result Cmd::process_sub_args_as_git_repo_paths() 423 : { 424 6 : if (get_manifest() == nullptr) return ESYSREPO_RESULT(ResultCode::MANIFEST_IS_NULLPTR); 425 : 426 3 : int result = 0; 427 : 428 3 : for (auto &input_path : get_sub_args()) 429 : { 430 0 : int local_result = process_sub_args_as_git_repo_path(input_path); 431 0 : if (local_result < 0) --result; 432 : } 433 3 : if (result < 0) 434 0 : return ESYSREPO_RESULT(ResultCode::CMD_GENERIC_RAW_ERROR, result); 435 : else 436 3 : return ESYSREPO_RESULT(ResultCode::OK); 437 : } 438 : 439 3 : const std::vector<std::string> &Cmd::get_input_git_repo_paths() const 440 : { 441 3 : return m_input_rel_git_repo_paths; 442 : } 443 : 444 73 : void Cmd::set_config_folder(std::shared_ptr<ConfigFolder> config_folder) 445 : { 446 73 : m_config_folder = config_folder; 447 73 : } 448 : 449 807 : std::shared_ptr<ConfigFolder> Cmd::get_config_folder() 450 : { 451 807 : return m_config_folder; 452 : } 453 : 454 713 : std::shared_ptr<ConfigFolder> Cmd::get_config_folder() const 455 : { 456 713 : return m_config_folder; 457 : } 458 : 459 64 : void Cmd::set_loader(std::shared_ptr<manifest::Loader> loader) 460 : { 461 64 : m_loader = loader; 462 64 : } 463 : 464 350 : std::shared_ptr<manifest::Loader> Cmd::get_loader() 465 : { 466 350 : return m_loader; 467 : } 468 : 469 41 : Result Cmd::open_esysrepo_folder() 470 : { 471 41 : auto config_folder = std::make_shared<ConfigFolder>(); 472 : 473 82 : set_config_folder(config_folder); 474 : 475 41 : boost::filesystem::path rel_parent_path = boost::filesystem::relative(get_workspace_path()); 476 41 : Result result = config_folder->open(get_workspace_path()); 477 41 : if (result.error()) 478 0 : error("Failed to open esysrepo folder : " + rel_parent_path.string()); 479 : else 480 82 : debug(0, "Opened esysrepo folder : " + rel_parent_path.string()); 481 : 482 82 : return ESYSREPO_RESULT(result); 483 82 : } 484 : 485 70 : Result Cmd::load_manifest() 486 : { 487 140 : if (get_config_folder() == nullptr) return ESYSREPO_RESULT(ResultCode::CMD_CONFIG_FOLDER_NULLPTR); 488 : 489 140 : if (get_loader() == nullptr) set_loader(std::make_shared<manifest::Loader>()); 490 140 : if (get_manifest() == nullptr) set_manifest(std::make_shared<Manifest>()); 491 70 : get_manifest()->clear(); 492 : 493 140 : get_loader()->set_manifest(get_manifest()); 494 140 : get_loader()->set_config_folder(get_config_folder()); 495 : 496 140 : get_loader()->set_logger_if(get_logger_if()); 497 70 : Result result = get_loader()->run(); 498 140 : return ESYSREPO_RESULT(result); 499 70 : } 500 : 501 66 : Result Cmd::ensure_manifest_loaded() 502 : { 503 103 : if (get_manifest() != nullptr) return ESYSREPO_RESULT(ResultCode::OK); 504 58 : if (get_config_folder() == nullptr) 505 : { 506 0 : Result result = open_esysrepo_folder(); 507 0 : if (result.error()) return ESYSREPO_RESULT(result); 508 0 : } 509 29 : return ESYSREPO_RESULT(load_manifest()); 510 : } 511 : 512 68 : void Cmd::set_nested_context(NestedContext *nested_context) 513 : { 514 68 : m_nested_context = nested_context; 515 68 : } 516 : 517 76 : NestedContext *Cmd::get_nested_context() const 518 : { 519 76 : return m_nested_context; 520 : } 521 : 522 36 : Result Cmd::default_handling_folder_workspace() 523 : { 524 36 : if (!get_folder().empty() && get_workspace_path().empty()) 525 : { 526 16 : boost::filesystem::path path = exe::Cmd::find_workspace_path(get_folder()); 527 8 : if (path.empty()) 528 : { 529 0 : std::string err_str = "Couldn't find a folder with ESysRepo from : " + get_folder(); 530 0 : error(err_str); 531 0 : return ESYSREPO_RESULT(ResultCode::CMD_NO_ESYSREPO_FOLDER_FOUND, err_str); 532 0 : } 533 24 : path = boost::filesystem::absolute(path).lexically_normal().make_preferred(); 534 8 : set_workspace_path(path.string()); 535 8 : } 536 28 : else if (!get_workspace_path().empty()) 537 : { 538 56 : boost::filesystem::path path = exe::Cmd::find_workspace_path(get_workspace_path()); 539 28 : if (path.empty()) 540 : { 541 0 : std::string err_str = "Couldn't find a folder with ESysRepo from : " + get_workspace_path(); 542 0 : error(err_str); 543 0 : return ESYSREPO_RESULT(ResultCode::CMD_NO_ESYSREPO_FOLDER_FOUND, err_str); 544 0 : } 545 84 : path = boost::filesystem::absolute(path).lexically_normal().make_preferred(); 546 28 : set_workspace_path(path.string()); 547 28 : } 548 : else 549 : { 550 0 : boost::filesystem::path path = exe::Cmd::find_workspace_path(); 551 0 : if (path.empty()) 552 : { 553 0 : std::string err_str = 554 0 : "Couldn't find a folder with ESysRepo from : " + boost::filesystem::current_path().string(); 555 0 : error(err_str); 556 0 : return ESYSREPO_RESULT(ResultCode::CMD_NO_ESYSREPO_FOLDER_FOUND, err_str); 557 0 : } 558 0 : path = boost::filesystem::absolute(path).lexically_normal().make_preferred(); 559 0 : set_workspace_path(path.string()); 560 0 : } 561 36 : return ESYSREPO_RESULT(ResultCode::OK); 562 : } 563 : 564 35 : Result Cmd::only_one_folder_or_workspace() 565 : { 566 35 : if (!get_folder().empty() && !get_workspace_path().empty()) 567 : { 568 0 : std::string err_str = "--folder and --workspace can't be specified at the same time"; 569 0 : error(err_str); 570 0 : return ESYSREPO_RESULT(ResultCode::CMD_INCORRECT_PARAMETERS_COMBINATION, err_str); 571 0 : } 572 35 : else if (!get_folder().empty() || !get_workspace_path().empty()) 573 : { 574 35 : boost::filesystem::path path; 575 35 : if (!get_folder().empty()) 576 4 : path = get_folder(); 577 : else 578 31 : path = get_workspace_path(); 579 105 : path = boost::filesystem::absolute(path).lexically_normal().make_preferred(); 580 35 : set_workspace_path(path.string()); 581 35 : } 582 : else 583 0 : set_workspace_path(boost::filesystem::current_path().lexically_normal().make_preferred().string()); 584 35 : return ESYSREPO_RESULT(ResultCode::OK); 585 : } 586 : 587 0 : Result Cmd::get_repo_branches(std::shared_ptr<manifest::Repository> repo, git::BranchType branch_type, 588 : git::Branches &branches) 589 : { 590 0 : auto git_helper = new_git_helper(); 591 : 592 0 : boost::filesystem::path rel_repo_path; 593 0 : boost::filesystem::path repo_path = /*get_config_folder()->*/ get_workspace_path(); 594 0 : repo_path /= repo->get_path(); 595 0 : repo_path = boost::filesystem::absolute(repo_path).lexically_normal().make_preferred(); 596 0 : rel_repo_path = boost::filesystem::relative(repo_path); 597 : 598 : // auto rel_repo_path = rel_repo_path.string(); 599 : // auto repo_path = repo_path.string(); 600 : 601 0 : branches.clear(); 602 : 603 0 : Result result = git_helper->open(repo_path.string(), log::Level::DEBUG); 604 0 : if (result.error()) return ESYSREPO_RESULT(result); 605 : 606 0 : auto last_commit = std::make_shared<git::CommitHash>(); 607 0 : result = get_git()->get_last_commit(*last_commit); 608 0 : if (result.error()) last_commit.reset(); 609 : 610 0 : result = git_helper->get_branches(branches, branch_type, log::Level::DEBUG); 611 0 : if (result.error()) 612 : { 613 0 : git_helper->close_on_error(log::Level::DEBUG); 614 0 : return ESYSREPO_RESULT(result); 615 : } 616 0 : result = git_helper->close(log::Level::DEBUG); 617 0 : return ESYSREPO_RESULT(result); 618 0 : } 619 : 620 0 : std::string Cmd::get_extra_start_msg() 621 : { 622 0 : return ""; 623 : } 624 : 625 20 : void Cmd::set_console_os(std::ostream *console_os) 626 : { 627 20 : m_console_os = console_os; 628 20 : } 629 : 630 9 : std::ostream *Cmd::get_console_os() 631 : { 632 9 : return m_console_os; 633 : } 634 : 635 9 : std::shared_ptr<esys::log::Mngr> Cmd::get_logger_mngr() 636 : { 637 9 : if (m_logger_mngr == nullptr) m_logger_mngr = esys::log::Mngr::get(); 638 9 : return m_logger_mngr; 639 : } 640 : 641 9 : const std::string &Cmd::get_logger_name() const 642 : { 643 9 : return m_logger_name; 644 : } 645 : 646 0 : void Cmd::set_logger_name(const std::string &logger_name) 647 : { 648 0 : m_logger_name = logger_name; 649 0 : } 650 : 651 9 : int Cmd::create_logger(const std::string &path) 652 : { 653 9 : auto logger = get_logger_mngr()->new_logger(log::LoggerType::SPDLOG, get_logger_name()); 654 9 : if (logger == nullptr) return -1; 655 : 656 9 : log::Level level = log::Level::DEBUG; 657 : 658 9 : logger->add_console(level); 659 9 : boost::filesystem::path log_path = path; 660 9 : if (log_path.empty()) log_path = boost::filesystem::current_path(); 661 9 : log_path /= "log.txt"; 662 9 : logger->add_basic_file(log_path.string()); 663 9 : logger->set_log_level(level); 664 9 : logger->set_debug_level(5); 665 9 : logger->set_flush_log_level(level); 666 18 : set_logger_if(logger); 667 9 : return 0; 668 18 : } 669 : 670 109 : void Cmd::debug(int level, const std::string &msg) 671 : { 672 109 : clean_cout(); 673 : 674 109 : User::debug(level, msg); 675 109 : } 676 : 677 394 : void Cmd::info(const std::string &msg) 678 : { 679 394 : clean_cout(); 680 : 681 394 : User::info(msg); 682 394 : } 683 : 684 1 : void Cmd::warn(const std::string &msg) 685 : { 686 1 : clean_cout(); 687 : 688 1 : User::warn(msg); 689 1 : } 690 : 691 4 : void Cmd::error(const std::string &msg) 692 : { 693 4 : clean_cout(); 694 : 695 4 : User::error(msg); 696 4 : } 697 : 698 0 : void Cmd::critical(const std::string &msg) 699 : { 700 0 : clean_cout(); 701 : 702 0 : User::critical(msg); 703 0 : } 704 : 705 0 : void Cmd::log(log::Level level, const std::string &msg) 706 : { 707 0 : clean_cout(); 708 : 709 0 : User::log(level, msg); 710 0 : } 711 : 712 0 : void Cmd::log(const std::string &msg, log::Level level, int debug_level) 713 : { 714 0 : clean_cout(); 715 : 716 0 : User::log(msg, level, debug_level); 717 0 : } 718 : 719 508 : void Cmd::clean_cout() 720 : { 721 : /*log::ConsoleLockGuard<log::User> lock(this); 722 : 723 : std::string s = " "; 724 : std::cout << "\r"; 725 : 726 : for (int idx = 0; idx < 8; ++idx) 727 : std::cout << s; 728 : std::cout << "\r"; */ 729 508 : } 730 : 731 56 : void Cmd::set_print_cmd_name_by_base(bool print_cmd_name_by_base) 732 : { 733 56 : m_print_cmd_name_by_base = print_cmd_name_by_base; 734 56 : } 735 : 736 85 : bool Cmd::get_print_cmd_name_by_base() const 737 : { 738 85 : return m_print_cmd_name_by_base; 739 : } 740 : 741 7 : void Cmd::set_print_result_summary(bool print_result_summary) 742 : { 743 7 : m_print_result_summary = print_result_summary; 744 7 : } 745 : 746 85 : bool Cmd::get_print_result_summary() const 747 : { 748 85 : return m_print_result_summary; 749 : } 750 : 751 112 : std::shared_ptr<GitHelper> Cmd::new_git_helper() 752 : { 753 224 : auto git_helper = std::make_shared<GitHelper>(get_git(), get_logger_if()); 754 : 755 336 : get_git()->set_logger_if(git_helper); 756 112 : return git_helper; 757 0 : } 758 : 759 81 : void Cmd::print_cmd_name() 760 : { 761 81 : std::ostringstream oss; 762 : 763 81 : print_cmd_name(oss); 764 81 : info(oss.str()); 765 81 : } 766 : 767 83 : void Cmd::print_cmd_name(std::ostream &os) 768 : { 769 83 : os << get_name() + " ..."; 770 83 : } 771 : 772 0 : Result Cmd::generic_error(int error) 773 : { 774 0 : if (error < 0) 775 0 : return ESYSREPO_RESULT(ResultCode::CMD_GENERIC_RAW_ERROR, error); 776 : else 777 0 : return ESYSREPO_RESULT(ResultCode::OK); 778 : } 779 : 780 : } // namespace esys::repo::exe