LCOV - code coverage report
Current view: top level - src/esys/repo/cli - cmdinit_cli.cpp (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 33 36 91.7 %
Date: 2026-08-01 10:43:40 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/cli/cmdinit_cli.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/cli/cmdinit.h"
      20             : 
      21             : #include <msword2md/cpp/string.h>
      22             : 
      23             : #include <termcolor/termcolor.hpp>
      24             : 
      25             : #include <boost/filesystem.hpp>
      26             : 
      27             : #include <vector>
      28             : 
      29             : namespace esys::repo::cli
      30             : {
      31             : 
      32             : #include "esys/repo/cli/cmdinit_doc.cpp"
      33             : 
      34          18 : CmdInit::CmdInit(AppBase *app)
      35          36 :     : BaseType(app, "init", "Initialize a repo client checkout in the current directory")
      36             : {
      37          18 : }
      38             : 
      39          18 : CmdInit::~CmdInit() = default;
      40             : 
      41           4 : std::shared_ptr<po::options_description> CmdInit::get_desc()
      42             : {
      43           4 :     auto desc = Cmd::get_desc();
      44           4 :     if (desc != nullptr) return desc;
      45             : 
      46           4 :     desc = std::make_shared<po::options_description>("Init options");
      47             :     // clang-format off
      48           4 :     desc->add_options()
      49           4 :         ("help,h", "produce help message")
      50           4 :         ("manifest-url,u", po::value<std::string>(), "manifest repository location")
      51           4 :         ("manifest-branch,b", po::value<std::string>(), "manifest branch or revision")
      52           4 :         ("manifest-name,m", po::value<std::string>(), "initial manifest file")
      53           4 :         ("project-name,p", po::value<std::string>(), "project name to find in a manifest directory")
      54           4 :         ("google,g", po::value<bool>()->default_value(false)->implicit_value(true), "google manifest")
      55           4 :         ("git-super,s", po::value<bool>()->default_value(false)->implicit_value(true), "git super project")
      56             :         ;
      57             :     // clang-format on
      58           8 :     Cmd::set_desc(desc);
      59           4 :     return desc;
      60           0 : }
      61             : 
      62          10 : int CmdInit::configure_cmd(CmdType &cmd)
      63             : {
      64          19 :     if (get_vm().count("manifest-url") && get_vm().count("project-name"))
      65             :     {
      66           0 :         error("--manifest-url and --project-name can't be specified at the same time");
      67           0 :         return -1;
      68             :     }
      69          11 :     else if ((get_vm().count("manifest-url") == 0) && (get_vm().count("project-name") == 0))
      70             :     {
      71           1 :         error("--manifest-url or --project-name must be specified");
      72           1 :         return -1;
      73             :     }
      74             : 
      75          36 :     if (get_vm().count("manifest-url")) get_cmd().set_url(get_vm()["manifest-url"].as<std::string>());
      76          18 :     if (get_vm().count("manifest-branch")) get_cmd().set_branch(get_vm()["manifest-branch"].as<std::string>());
      77          18 :     if (get_vm().count("manifest-name")) get_cmd().set_manifest_name(get_vm()["manifest-name"].as<std::string>());
      78          18 :     if (get_vm().count("project-name")) get_cmd().set_project_name(get_vm()["project-name"].as<std::string>());
      79          18 :     get_cmd().set_google_manifest(get_vm()["google"].as<bool>());
      80          18 :     get_cmd().set_git_super_project(get_vm()["git-super"].as<bool>());
      81             : 
      82           9 :     return 0;
      83             : }
      84             : 
      85           1 : int CmdInit::print_doc(std::ostream &os)
      86             : {
      87           1 :     os << cmdinit_doc_strings;
      88           1 :     return 0;
      89             : }
      90             : 
      91             : } // namespace esys::repo::cli

Generated by: LCOV version 1.14