LCOV - code coverage report
Current view: top level - src/esys/repo/exe - cmdhelp.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 26 31 83.9 %
Date: 2026-08-01 10:43:40 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/exe/cmdhelp.cpp
       3             :  * \brief
       4             :  *
       5             :  * \cond
       6             :  * __legal_b__
       7             :  *
       8             :  * Copyright (c) 2020-2021 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/cmdhelp.h"
      20             : #include "esys/repo/cli/appbase.h"
      21             : 
      22             : #include <termcolor/termcolor.hpp>
      23             : 
      24             : #include <sstream>
      25             : #include <iomanip>
      26             : #include <cassert>
      27             : #include <iostream>
      28             : 
      29             : namespace esys::repo::exe
      30             : {
      31             : 
      32          17 : CmdHelp::CmdHelp()
      33          17 :     : Cmd("Help")
      34             : {
      35          17 : }
      36             : 
      37          17 : CmdHelp::~CmdHelp() = default;
      38             : 
      39           2 : Result CmdHelp::impl_run()
      40             : {
      41           2 :     std::ostringstream oss;
      42           2 :     std::ostringstream oss_help;
      43           2 :     int result = 0;
      44             :     // info("Help ...");
      45             : 
      46           2 :     assert(get_app_base() != nullptr);
      47             : 
      48           2 :     if (get_sub_args().size() == 0)
      49             :     {
      50           1 :         std::string err_str = "At least one command should be given.";
      51           1 :         error(err_str);
      52           1 :         return ESYSREPO_RESULT(ResultCode::CMD_MISSING_PARAMETERS, err_str);
      53           1 :     }
      54             : 
      55           3 :     for (auto &cmd_txt : get_sub_args())
      56             :     {
      57           4 :         oss.str("");
      58           2 :         cli::Cmd *cmd = get_app_base()->find_cmd(cmd_txt);
      59           2 :         if (cmd == nullptr)
      60             :         {
      61           0 :             error("Unknown command '" + cmd_txt + "'.");
      62           0 :             continue;
      63             :         }
      64           2 :         oss << "Command '" << cmd_txt << "':" << std::endl;
      65           2 :         result = cmd->print_doc(oss_help);
      66           2 :         if (result < 0)
      67             :         {
      68           0 :             oss << *cmd->get_desc_all();
      69           0 :             info(oss.str());
      70             :         }
      71             :         else
      72             :         {
      73           2 :             info(oss.str());
      74           2 :             if (get_console_os() != nullptr)
      75           0 :                 cmd->print_doc(*get_console_os());
      76             :             else
      77           2 :                 std::cout << oss_help.str();
      78             :         }
      79             :     }
      80             :     // info("Help done.");
      81           1 :     return ESYSREPO_RESULT(ResultCode::OK);
      82           2 : }
      83             : 
      84             : } // namespace esys::repo::exe

Generated by: LCOV version 1.14