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: 57 58 98.3 %
Date: 2026-09-26 15:38:18 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 <esys/md/rend/styled_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          23 : CmdInit::CmdInit(AppBase *app)
      35          46 :     : BaseType(app, "init", "Initialize a repo client checkout in the current directory")
      36             : {
      37          23 : }
      38             : 
      39          23 : CmdInit::~CmdInit() = default;
      40             : 
      41           9 : std::shared_ptr<po::options_description> CmdInit::get_desc()
      42             : {
      43           9 :     auto desc = Cmd::get_desc();
      44           9 :     if (desc != nullptr) return desc;
      45             : 
      46           9 :     desc = std::make_shared<po::options_description>("Init options");
      47             :     // clang-format off
      48           9 :     desc->add_options()
      49           9 :         ("help,h", "produce help message")
      50           9 :         ("manifest-url,u", po::value<std::string>(), "manifest repository location")
      51           9 :         ("manifest-local,l", po::value<std::string>(), "local manifest file or folder")
      52           9 :         ("manifest-branch,b", po::value<std::string>(), "manifest branch or revision")
      53           9 :         ("manifest-name,m", po::value<std::string>(), "initial manifest file")
      54           9 :         ("project-name,p", po::value<std::string>(), "project name to find in a manifest directory")
      55           9 :         ("rev-set", po::value<std::string>(), "native manifest revision-set name")
      56           9 :         ("prefer-branch", po::value<std::string>(),
      57             :          "prefer this project branch when it exists; stored for later sync")
      58           9 :         ("strict", po::value<bool>()->default_value(false)->implicit_value(true),
      59             :          "fail on unknown manifest XML (default tolerant; stored as parse_mode in .esysrepo/config.json)")
      60           9 :         ("google,g", po::value<bool>()->default_value(false)->implicit_value(true), "google manifest")
      61           9 :         ("git-super,s", po::value<bool>()->default_value(false)->implicit_value(true), "git super project")
      62             :         ;
      63             :     // clang-format on
      64          18 :     Cmd::set_desc(desc);
      65           9 :     return desc;
      66           0 : }
      67             : 
      68          18 : int CmdInit::configure_cmd(CmdType &cmd)
      69             : {
      70          18 :     const int source_count = static_cast<int>(get_vm().count("manifest-url"))
      71          36 :         + static_cast<int>(get_vm().count("project-name"))
      72          36 :         + static_cast<int>(get_vm().count("manifest-local"));
      73          18 :     if (source_count > 1)
      74             :     {
      75           1 :         error("--manifest-url, --project-name, and --manifest-local are mutually exclusive");
      76           1 :         return -1;
      77             :     }
      78          17 :     if (source_count == 0)
      79             :     {
      80           1 :         error("--manifest-url, --project-name, or --manifest-local must be specified");
      81           1 :         return -1;
      82             :     }
      83          18 :     if (get_vm().count("manifest-local") && get_vm().count("manifest-branch"))
      84             :     {
      85           1 :         error("--manifest-branch / -b cannot be combined with --manifest-local / -l");
      86           1 :         return -1;
      87             :     }
      88             : 
      89             :     // Each parse replaces prior source fields so a reused CmdInit (and tests)
      90             :     // does not keep -u / -p / -b after a later -l-only argv.
      91          15 :     cmd.set_url({});
      92          15 :     cmd.set_manifest_local({});
      93          15 :     cmd.set_project_name({});
      94          15 :     cmd.set_branch({});
      95          15 :     cmd.set_manifest_name({});
      96          15 :     cmd.set_rev_set({});
      97          15 :     cmd.set_prefer_branch({});
      98          15 :     cmd.set_parse_mode(manifest::k_default_parse_mode);
      99             : 
     100          58 :     if (get_vm().count("manifest-url")) cmd.set_url(get_vm()["manifest-url"].as<std::string>());
     101          32 :     if (get_vm().count("manifest-local")) cmd.set_manifest_local(get_vm()["manifest-local"].as<std::string>());
     102          32 :     if (get_vm().count("manifest-branch")) cmd.set_branch(get_vm()["manifest-branch"].as<std::string>());
     103          30 :     if (get_vm().count("manifest-name")) cmd.set_manifest_name(get_vm()["manifest-name"].as<std::string>());
     104          30 :     if (get_vm().count("project-name")) cmd.set_project_name(get_vm()["project-name"].as<std::string>());
     105          32 :     if (get_vm().count("rev-set")) cmd.set_rev_set(get_vm()["rev-set"].as<std::string>());
     106          34 :     if (get_vm().count("prefer-branch")) cmd.set_prefer_branch(get_vm()["prefer-branch"].as<std::string>());
     107          30 :     if (get_vm()["strict"].as<bool>()) cmd.set_parse_mode(manifest::ParseMode::Strict);
     108          30 :     cmd.set_google_manifest(get_vm()["google"].as<bool>());
     109          30 :     cmd.set_git_super_project(get_vm()["git-super"].as<bool>());
     110             : 
     111          15 :     return 0;
     112             : }
     113             : 
     114           1 : int CmdInit::print_doc(std::ostream &os)
     115             : {
     116           1 :     os << cmdinit_doc_strings;
     117           1 :     return 0;
     118             : }
     119             : 
     120             : } // namespace esys::repo::cli

Generated by: LCOV version 1.14