LCOV - code coverage report
Current view: top level - src/esys/repo/exe - cmd.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 257 401 64.1 %
Date: 2026-08-01 10:43:40 Functions: 60 77 77.9 %

          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         217 : Cmd::Cmd(const std::string &name)
      39             :     : log::User()
      40         217 :     , m_name(name)
      41             : {
      42         217 : }
      43             : 
      44         426 : Cmd::~Cmd() = default;
      45             : 
      46         112 : const std::string &Cmd::get_name() const
      47             : {
      48         112 :     return m_name;
      49             : }
      50             : 
      51          23 : void Cmd::set_job_count(int job_count)
      52             : {
      53          23 :     m_job_count = job_count;
      54          23 : }
      55             : 
      56          21 : int Cmd::get_job_count() const
      57             : {
      58          21 :     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          52 : void Cmd::set_user_folder(std::shared_ptr<UserFolder> user_folder)
      72             : {
      73          52 :     m_user_folder = user_folder;
      74          52 : }
      75             : 
      76         116 : std::shared_ptr<UserFolder> Cmd::get_user_folder() const
      77             : {
      78         116 :     return m_user_folder;
      79             : }
      80             : 
      81          58 : Result Cmd::load_or_create_user_config()
      82             : {
      83         116 :     if (get_user_folder() == nullptr) set_user_folder(std::make_shared<UserFolder>());
      84             : 
      85          58 :     auto user_folder = get_user_folder();
      86          58 :     auto result = user_folder->read();
      87          58 :     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         116 :         info("User config file loaded successfully.");
     102             : 
     103          58 :     return ESYSREPO_RESULT(ResultCode::OK);
     104         116 : }
     105             : 
     106          58 : Result Cmd::run()
     107             : {
     108          58 :     m_start_time = std::chrono::steady_clock::now();
     109             : 
     110          58 :     if (get_print_cmd_name_by_base()) print_cmd_name();
     111             : 
     112         116 :     if (get_git() == nullptr) set_git(GitMngr::new_ptr());
     113         232 :     if (get_logger_if() != nullptr) get_git()->set_logger_if(get_logger_if());
     114             : 
     115          58 :     Result result = load_or_create_user_config();
     116          58 :     if (result.error())
     117             :     {
     118           0 :         error("Some features will not work because the user config file issues.");
     119             :     }
     120          58 :     result = impl_run();
     121             : 
     122          58 :     auto stop_time = std::chrono::steady_clock::now();
     123          58 :     auto d_milli = std::chrono::duration_cast<std::chrono::milliseconds>(stop_time - m_start_time).count();
     124             : 
     125          58 :     if (get_print_result_summary())
     126             :     {
     127          56 :         std::ostringstream oss;
     128          56 :         std::string msg;
     129             : 
     130          56 :         msg = get_name();
     131          56 :         oss << "    elapsed time (s): " << (d_milli / THOUSAND) << "." << (d_milli % THOUSAND);
     132          56 :         if (result.ok())
     133             :         {
     134          55 :             msg += " done.\n";
     135         110 :             msg += oss.str();
     136          55 :             info(msg);
     137             :         }
     138             :         else
     139             :         {
     140           1 :             msg += " failed.\n";
     141           2 :             msg += oss.str();
     142           1 :             error(msg);
     143             :         }
     144          56 :     }
     145         174 :     return ESYSREPO_RESULT(result);
     146          58 : }
     147             : 
     148          27 : void Cmd::set_manifest(std::shared_ptr<Manifest> manifest)
     149             : {
     150          27 :     m_manifest = manifest;
     151          27 : }
     152             : 
     153         209 : std::shared_ptr<Manifest> Cmd::get_manifest() const
     154             : {
     155         209 :     return m_manifest;
     156             : }
     157             : 
     158          57 : void Cmd::set_git(std::shared_ptr<GitBase> git)
     159             : {
     160          57 :     m_git = git;
     161          57 : }
     162             : 
     163         414 : std::shared_ptr<GitBase> Cmd::get_git() const
     164             : {
     165         414 :     return m_git;
     166             : }
     167             : 
     168         142 : void Cmd::set_workspace_path(const std::string &workspace_path)
     169             : {
     170         142 :     m_workspace_path = workspace_path;
     171         142 : }
     172             : 
     173         249 : const std::string &Cmd::get_workspace_path() const
     174             : {
     175         573 :     if ((get_config_folder() != nullptr) && (!get_config_folder()->get_workspace_path().empty()))
     176         112 :         return get_config_folder()->get_workspace_path();
     177         193 :     return m_workspace_path;
     178             : }
     179             : 
     180          28 : std::string Cmd::find_workspace_path(const std::string &path)
     181             : {
     182          28 :     boost::filesystem::path cur_path;
     183             : 
     184          28 :     if (!path.empty())
     185          28 :         cur_path = path;
     186             :     else
     187           0 :         cur_path = boost::filesystem::current_path();
     188             : 
     189          28 :     while (!cur_path.empty())
     190             :     {
     191          28 :         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          28 : }
     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          76 : void Cmd::set_debug(bool debug)
     217             : {
     218          76 :     m_debug = debug;
     219          76 : }
     220             : 
     221          20 : bool Cmd::get_debug() const
     222             : {
     223          20 :     return m_debug;
     224             : }
     225             : 
     226          48 : void Cmd::set_folder(const std::string &folder)
     227             : {
     228          48 :     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          48 : }
     235             : 
     236         114 : const std::string &Cmd::get_folder() const
     237             : {
     238         114 :     return m_folder;
     239             : }
     240             : 
     241           1 : bool Cmd::is_git_root_folder(const std::string &path)
     242             : {
     243           1 :     boost::filesystem::path folder_path = path;
     244             : 
     245           1 :     folder_path /= ".git";
     246           1 :     return boost::filesystem::exists(folder_path);
     247           1 : }
     248             : 
     249           1 : std::string Cmd::find_git_root_path(const std::string &folder_path)
     250             : {
     251           1 :     boost::filesystem::path cur_path = folder_path;
     252             : 
     253           1 :     while (!cur_path.empty())
     254             :     {
     255           1 :         if (is_git_root_folder(cur_path.string()))
     256             :         {
     257           1 :             return cur_path.string();
     258             :         }
     259           0 :         cur_path = cur_path.parent_path();
     260             :     }
     261           0 :     return "";
     262           1 : }
     263             : 
     264           1 : Result Cmd::load_capture(std::shared_ptr<manifest::Capture> capture, const std::string &note_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 &note_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          58 : void Cmd::set_sub_args(const std::vector<std::string> &sub_args)
     297             : {
     298          58 :     m_sub_args = sub_args;
     299          58 : }
     300             : 
     301          32 : const std::vector<std::string> &Cmd::get_sub_args() const
     302             : {
     303          32 :     return m_sub_args;
     304             : }
     305             : 
     306          48 : void Cmd::set_time(bool time)
     307             : {
     308          48 :     m_time = time;
     309          48 : }
     310             : 
     311           0 : bool Cmd::get_time() const
     312             : {
     313           0 :     return m_time;
     314             : }
     315             : 
     316          48 : void Cmd::set_delta_time(bool delta_time)
     317             : {
     318          48 :     m_delta_time = delta_time;
     319          48 : }
     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          18 : const std::vector<std::string> &Cmd::get_groups() const
     332             : {
     333          18 :     return m_groups;
     334             : }
     335             : 
     336         171 : void Cmd::set_cli_cmd(cli::Cmd *cli_cmd)
     337             : {
     338         171 :     m_cli_cmd = cli_cmd;
     339         171 : }
     340             : 
     341           0 : cli::Cmd *Cmd::get_cli_cmd()
     342             : {
     343           0 :     return m_cli_cmd;
     344             : }
     345             : 
     346         171 : void Cmd::set_app_base(cli::AppBase *app_base)
     347             : {
     348         171 :     m_app_base = app_base;
     349         171 : }
     350             : 
     351           2 : cli::AppBase *Cmd::get_app_base()
     352             : {
     353           2 :     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()) return 0;
     380             : 
     381           0 :     if (!boost::filesystem::exists(the_input_path))
     382             :     {
     383             :         // The input path doesn't exist
     384             :         // Couldn't it be the relative path of a git repo in the manifest?
     385           0 :         auto repo = get_manifest()->find_repo_by_path(the_input_path.string());
     386           0 :         if (repo == nullptr)
     387             :         {
     388           0 :             error("The given path doesn't exists : " + the_input_path.string());
     389           0 :             return -1;
     390             :         }
     391             : 
     392             :         // This was indeed the relative path of a git repo in the manifest
     393           0 :         git_repo = the_input_path.string();
     394           0 :     }
     395             :     else
     396             :     {
     397             :         // We need to find which repo this is related too
     398           0 :         boost::filesystem::path git_rel_path = boost::filesystem::relative(git_repo, workspace_path);
     399             : 
     400           0 :         if (git_rel_path.empty())
     401             :         {
     402           0 :             error("The following git repo doesn't seem to be known by ESysRepo: " + git_repo.string());
     403           0 :             return -1;
     404             :         }
     405           0 :         git_repo = git_rel_path;
     406           0 :     }
     407           0 :     m_input_rel_git_repo_paths.push_back(git_repo.generic_path().string());
     408           0 :     return 0;
     409           0 : }
     410             : 
     411           3 : Result Cmd::process_sub_args_as_git_repo_paths()
     412             : {
     413           6 :     if (get_manifest() == nullptr) return ESYSREPO_RESULT(ResultCode::MANIFEST_IS_NULLPTR);
     414             : 
     415           3 :     int result = 0;
     416             : 
     417           3 :     for (auto &input_path : get_sub_args())
     418             :     {
     419           0 :         int local_result = process_sub_args_as_git_repo_path(input_path);
     420           0 :         if (local_result < 0) --result;
     421             :     }
     422           3 :     if (result < 0)
     423           0 :         return ESYSREPO_RESULT(ResultCode::CMD_GENERIC_RAW_ERROR, result);
     424             :     else
     425           3 :         return ESYSREPO_RESULT(ResultCode::OK);
     426             : }
     427             : 
     428           3 : const std::vector<std::string> &Cmd::get_input_git_repo_paths() const
     429             : {
     430           3 :     return m_input_rel_git_repo_paths;
     431             : }
     432             : 
     433          53 : void Cmd::set_config_folder(std::shared_ptr<ConfigFolder> config_folder)
     434             : {
     435          53 :     m_config_folder = config_folder;
     436          53 : }
     437             : 
     438         317 : std::shared_ptr<ConfigFolder> Cmd::get_config_folder()
     439             : {
     440         317 :     return m_config_folder;
     441             : }
     442             : 
     443         467 : std::shared_ptr<ConfigFolder> Cmd::get_config_folder() const
     444             : {
     445         467 :     return m_config_folder;
     446             : }
     447             : 
     448          27 : void Cmd::set_loader(std::shared_ptr<manifest::Loader> loader)
     449             : {
     450          27 :     m_loader = loader;
     451          27 : }
     452             : 
     453         160 : std::shared_ptr<manifest::Loader> Cmd::get_loader()
     454             : {
     455         160 :     return m_loader;
     456             : }
     457             : 
     458          32 : Result Cmd::open_esysrepo_folder()
     459             : {
     460          32 :     auto config_folder = std::make_shared<ConfigFolder>();
     461             : 
     462          64 :     set_config_folder(config_folder);
     463             : 
     464          32 :     boost::filesystem::path rel_parent_path = boost::filesystem::relative(get_workspace_path());
     465          32 :     Result result = config_folder->open(get_workspace_path());
     466          32 :     if (result.error())
     467           0 :         error("Failed to open esysrepo folder : " + rel_parent_path.string());
     468             :     else
     469          64 :         debug(0, "Opened esysrepo folder : " + rel_parent_path.string());
     470             : 
     471          64 :     return ESYSREPO_RESULT(result);
     472          64 : }
     473             : 
     474          32 : Result Cmd::load_manifest()
     475             : {
     476          64 :     if (get_config_folder() == nullptr) return ESYSREPO_RESULT(ResultCode::CMD_CONFIG_FOLDER_NULLPTR);
     477             : 
     478          64 :     if (get_loader() == nullptr) set_loader(std::make_shared<manifest::Loader>());
     479          64 :     if (get_manifest() == nullptr) set_manifest(std::make_shared<Manifest>());
     480          32 :     get_manifest()->clear();
     481             : 
     482          64 :     get_loader()->set_manifest(get_manifest());
     483          64 :     get_loader()->set_config_folder(get_config_folder());
     484             : 
     485          64 :     get_loader()->set_logger_if(get_logger_if());
     486          32 :     Result result = get_loader()->run();
     487          64 :     return ESYSREPO_RESULT(result);
     488          32 : }
     489             : 
     490          28 : Result Cmd::default_handling_folder_workspace()
     491             : {
     492          28 :     if (!get_folder().empty() && get_workspace_path().empty())
     493             :     {
     494          16 :         boost::filesystem::path path = exe::Cmd::find_workspace_path(get_folder());
     495           8 :         if (path.empty())
     496             :         {
     497           0 :             std::string err_str = "Couldn't find a folder with ESysRepo from : " + get_folder();
     498           0 :             error(err_str);
     499           0 :             return ESYSREPO_RESULT(ResultCode::CMD_NO_ESYSREPO_FOLDER_FOUND, err_str);
     500           0 :         }
     501          24 :         path = boost::filesystem::absolute(path).lexically_normal().make_preferred();
     502           8 :         set_workspace_path(path.string());
     503           8 :     }
     504          20 :     else if (!get_workspace_path().empty())
     505             :     {
     506          40 :         boost::filesystem::path path = exe::Cmd::find_workspace_path(get_workspace_path());
     507          20 :         if (path.empty())
     508             :         {
     509           0 :             std::string err_str = "Couldn't find a folder with ESysRepo from : " + get_workspace_path();
     510           0 :             error(err_str);
     511           0 :             return ESYSREPO_RESULT(ResultCode::CMD_NO_ESYSREPO_FOLDER_FOUND, err_str);
     512           0 :         }
     513          60 :         path = boost::filesystem::absolute(path).lexically_normal().make_preferred();
     514          20 :         set_workspace_path(path.string());
     515          20 :     }
     516             :     else
     517             :     {
     518           0 :         boost::filesystem::path path = exe::Cmd::find_workspace_path();
     519           0 :         if (path.empty())
     520             :         {
     521           0 :             std::string err_str =
     522           0 :                 "Couldn't find a folder with ESysRepo from : " + boost::filesystem::current_path().string();
     523           0 :             error(err_str);
     524           0 :             return ESYSREPO_RESULT(ResultCode::CMD_NO_ESYSREPO_FOLDER_FOUND, err_str);
     525           0 :         }
     526           0 :         path = boost::filesystem::absolute(path).lexically_normal().make_preferred();
     527           0 :         set_workspace_path(path.string());
     528           0 :     }
     529          28 :     return ESYSREPO_RESULT(ResultCode::OK);
     530             : }
     531             : 
     532          24 : Result Cmd::only_one_folder_or_workspace()
     533             : {
     534          24 :     if (!get_folder().empty() && !get_workspace_path().empty())
     535             :     {
     536           0 :         std::string err_str = "--folder and --workspace can't be specified at the same time";
     537           0 :         error(err_str);
     538           0 :         return ESYSREPO_RESULT(ResultCode::CMD_INCORRECT_PARAMETERS_COMBINATION, err_str);
     539           0 :     }
     540          24 :     else if (!get_folder().empty() || !get_workspace_path().empty())
     541             :     {
     542          24 :         boost::filesystem::path path;
     543          24 :         if (!get_folder().empty())
     544           4 :             path = get_folder();
     545             :         else
     546          20 :             path = get_workspace_path();
     547          72 :         path = boost::filesystem::absolute(path).lexically_normal().make_preferred();
     548          24 :         set_workspace_path(path.string());
     549          24 :     }
     550             :     else
     551           0 :         set_workspace_path(boost::filesystem::current_path().lexically_normal().make_preferred().string());
     552          24 :     return ESYSREPO_RESULT(ResultCode::OK);
     553             : }
     554             : 
     555           0 : Result Cmd::get_repo_branches(std::shared_ptr<manifest::Repository> repo, git::BranchType branch_type,
     556             :                               git::Branches &branches)
     557             : {
     558           0 :     auto git_helper = new_git_helper();
     559             : 
     560           0 :     boost::filesystem::path rel_repo_path;
     561           0 :     boost::filesystem::path repo_path = /*get_config_folder()->*/ get_workspace_path();
     562           0 :     repo_path /= repo->get_path();
     563           0 :     repo_path = boost::filesystem::absolute(repo_path).lexically_normal().make_preferred();
     564           0 :     rel_repo_path = boost::filesystem::relative(repo_path);
     565             : 
     566             :     // auto rel_repo_path = rel_repo_path.string();
     567             :     // auto repo_path = repo_path.string();
     568             : 
     569           0 :     branches.clear();
     570             : 
     571           0 :     Result result = git_helper->open(repo_path.string(), log::Level::DEBUG);
     572           0 :     if (result.error()) return ESYSREPO_RESULT(result);
     573             : 
     574           0 :     auto last_commit = std::make_shared<git::CommitHash>();
     575           0 :     result = get_git()->get_last_commit(*last_commit);
     576           0 :     if (result.error()) last_commit.reset();
     577             : 
     578           0 :     result = git_helper->get_branches(branches, branch_type, log::Level::DEBUG);
     579           0 :     if (result.error())
     580             :     {
     581           0 :         git_helper->close_on_error(log::Level::DEBUG);
     582           0 :         return ESYSREPO_RESULT(result);
     583             :     }
     584           0 :     result = git_helper->close(log::Level::DEBUG);
     585           0 :     return ESYSREPO_RESULT(result);
     586           0 : }
     587             : 
     588           0 : std::string Cmd::get_extra_start_msg()
     589             : {
     590           0 :     return "";
     591             : }
     592             : 
     593          18 : void Cmd::set_console_os(std::ostream *console_os)
     594             : {
     595          18 :     m_console_os = console_os;
     596          18 : }
     597             : 
     598           4 : std::ostream *Cmd::get_console_os()
     599             : {
     600           4 :     return m_console_os;
     601             : }
     602             : 
     603           4 : std::shared_ptr<esys::log::Mngr> Cmd::get_logger_mngr()
     604             : {
     605           4 :     if (m_logger_mngr == nullptr) m_logger_mngr = esys::log::Mngr::get();
     606           4 :     return m_logger_mngr;
     607             : }
     608             : 
     609           4 : const std::string &Cmd::get_logger_name() const
     610             : {
     611           4 :     return m_logger_name;
     612             : }
     613             : 
     614           0 : void Cmd::set_logger_name(const std::string &logger_name)
     615             : {
     616           0 :     m_logger_name = logger_name;
     617           0 : }
     618             : 
     619           4 : int Cmd::create_logger(const std::string &path)
     620             : {
     621           4 :     auto logger = get_logger_mngr()->new_logger(log::LoggerType::SPDLOG, get_logger_name());
     622           4 :     if (logger == nullptr) return -1;
     623             : 
     624           4 :     log::Level level = log::Level::DEBUG;
     625             : 
     626           4 :     logger->add_console(level);
     627           4 :     boost::filesystem::path log_path = path;
     628           4 :     if (log_path.empty()) log_path = boost::filesystem::current_path();
     629           4 :     log_path /= "log.txt";
     630           4 :     logger->add_basic_file(log_path.string());
     631           4 :     logger->set_log_level(level);
     632           4 :     logger->set_debug_level(5);
     633           4 :     logger->set_flush_log_level(level);
     634           8 :     set_logger_if(logger);
     635           4 :     return 0;
     636           8 : }
     637             : 
     638          80 : void Cmd::debug(int level, const std::string &msg)
     639             : {
     640          80 :     clean_cout();
     641             : 
     642          80 :     User::debug(level, msg);
     643          80 : }
     644             : 
     645         249 : void Cmd::info(const std::string &msg)
     646             : {
     647         249 :     clean_cout();
     648             : 
     649         249 :     User::info(msg);
     650         249 : }
     651             : 
     652           1 : void Cmd::warn(const std::string &msg)
     653             : {
     654           1 :     clean_cout();
     655             : 
     656           1 :     User::warn(msg);
     657           1 : }
     658             : 
     659           4 : void Cmd::error(const std::string &msg)
     660             : {
     661           4 :     clean_cout();
     662             : 
     663           4 :     User::error(msg);
     664           4 : }
     665             : 
     666           0 : void Cmd::critical(const std::string &msg)
     667             : {
     668           0 :     clean_cout();
     669             : 
     670           0 :     User::critical(msg);
     671           0 : }
     672             : 
     673           0 : void Cmd::log(log::Level level, const std::string &msg)
     674             : {
     675           0 :     clean_cout();
     676             : 
     677           0 :     User::log(level, msg);
     678           0 : }
     679             : 
     680           0 : void Cmd::log(const std::string &msg, log::Level level, int debug_level)
     681             : {
     682           0 :     clean_cout();
     683             : 
     684           0 :     User::log(msg, level, debug_level);
     685           0 : }
     686             : 
     687         334 : void Cmd::clean_cout()
     688             : {
     689             :     /*log::ConsoleLockGuard<log::User> lock(this);
     690             : 
     691             :     std::string s = "             ";
     692             :     std::cout << "\r";
     693             : 
     694             :     for (int idx = 0; idx < 8; ++idx)
     695             :         std::cout << s;
     696             :     std::cout << "\r"; */
     697         334 : }
     698             : 
     699          37 : void Cmd::set_print_cmd_name_by_base(bool print_cmd_name_by_base)
     700             : {
     701          37 :     m_print_cmd_name_by_base = print_cmd_name_by_base;
     702          37 : }
     703             : 
     704          58 : bool Cmd::get_print_cmd_name_by_base() const
     705             : {
     706          58 :     return m_print_cmd_name_by_base;
     707             : }
     708             : 
     709           4 : void Cmd::set_print_result_summary(bool print_result_summary)
     710             : {
     711           4 :     m_print_result_summary = print_result_summary;
     712           4 : }
     713             : 
     714          58 : bool Cmd::get_print_result_summary() const
     715             : {
     716          58 :     return m_print_result_summary;
     717             : }
     718             : 
     719          98 : std::shared_ptr<GitHelper> Cmd::new_git_helper()
     720             : {
     721         196 :     auto git_helper = std::make_shared<GitHelper>(get_git(), get_logger_if());
     722             : 
     723         294 :     get_git()->set_logger_if(git_helper);
     724          98 :     return git_helper;
     725           0 : }
     726             : 
     727          54 : void Cmd::print_cmd_name()
     728             : {
     729          54 :     std::ostringstream oss;
     730             : 
     731          54 :     print_cmd_name(oss);
     732          54 :     info(oss.str());
     733          54 : }
     734             : 
     735          56 : void Cmd::print_cmd_name(std::ostream &os)
     736             : {
     737          56 :     os << get_name() + " ...";
     738          56 : }
     739             : 
     740           0 : Result Cmd::generic_error(int error)
     741             : {
     742           0 :     if (error < 0)
     743           0 :         return ESYSREPO_RESULT(ResultCode::CMD_GENERIC_RAW_ERROR, error);
     744             :     else
     745           0 :         return ESYSREPO_RESULT(ResultCode::OK);
     746             : }
     747             : 
     748             : } // namespace esys::repo::exe

Generated by: LCOV version 1.14