LCOV - code coverage report
Current view: top level - src/esys/repo/exe - cmdenv.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 5 22 22.7 %
Date: 2026-08-01 10:43:40 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/exe/cmdenv.cpp
       3             :  * \brief
       4             :  *
       5             :  * \cond
       6             :  * __legal_b__
       7             :  *
       8             :  * Copyright (c) 2022 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/cmdenv.h"
      20             : 
      21             : #include <boost/process/environment.hpp>
      22             : 
      23             : #include <sstream>
      24             : #include <iomanip>
      25             : 
      26             : namespace esys::repo::exe
      27             : {
      28             : 
      29          16 : CmdEnv::CmdEnv()
      30          16 :     : Cmd("Env")
      31             : {
      32          16 :     set_print_cmd_name_by_base(false);
      33          16 : }
      34             : 
      35          16 : CmdEnv::~CmdEnv() = default;
      36             : 
      37           0 : Result CmdEnv::impl_run()
      38             : {
      39           0 :     std::ostringstream oss;
      40             : 
      41           0 :     print_cmd_name(oss);
      42           0 :     oss << std::endl;
      43             : 
      44           0 :     auto env = boost::this_process::environment();
      45             : 
      46           0 :     std::size_t max_name_size = 0;
      47             : 
      48           0 :     for (auto item : env)
      49             :     {
      50           0 :         std::string name = item.get_name();
      51           0 :         if (name.size() > max_name_size) max_name_size = name.size();
      52           0 :     }
      53             : 
      54           0 :     for (auto item : env)
      55             :     {
      56           0 :         oss << std::setw(max_name_size + 1) << std::left << item.get_name() << " = ";
      57           0 :         oss << item.to_string() << std::endl;
      58           0 :     }
      59             : 
      60           0 :     info(oss.str());
      61           0 :     return ESYSREPO_RESULT(ResultCode::OK);
      62           0 : }
      63             : 
      64             : } // namespace esys::repo::exe

Generated by: LCOV version 1.14