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 21 : CmdInit::CmdInit(AppBase *app) 35 42 : : BaseType(app, "init", "Initialize a repo client checkout in the current directory") 36 : { 37 21 : } 38 : 39 21 : CmdInit::~CmdInit() = default; 40 : 41 7 : std::shared_ptr<po::options_description> CmdInit::get_desc() 42 : { 43 7 : auto desc = Cmd::get_desc(); 44 7 : if (desc != nullptr) return desc; 45 : 46 7 : desc = std::make_shared<po::options_description>("Init options"); 47 : // clang-format off 48 7 : desc->add_options() 49 7 : ("help,h", "produce help message") 50 7 : ("manifest-url,u", po::value<std::string>(), "manifest repository location") 51 7 : ("manifest-branch,b", po::value<std::string>(), "manifest branch or revision") 52 7 : ("manifest-name,m", po::value<std::string>(), "initial manifest file") 53 7 : ("project-name,p", po::value<std::string>(), "project name to find in a manifest directory") 54 7 : ("rev-set", po::value<std::string>(), "native manifest revision-set name") 55 7 : ("strict", po::value<bool>()->default_value(false)->implicit_value(true), 56 : "fail on unknown manifest XML (default tolerant; stored as parse_mode in .esysrepo/config.json)") 57 7 : ("google,g", po::value<bool>()->default_value(false)->implicit_value(true), "google manifest") 58 7 : ("git-super,s", po::value<bool>()->default_value(false)->implicit_value(true), "git super project") 59 : ; 60 : // clang-format on 61 14 : Cmd::set_desc(desc); 62 7 : return desc; 63 0 : } 64 : 65 13 : int CmdInit::configure_cmd(CmdType &cmd) 66 : { 67 25 : if (get_vm().count("manifest-url") && get_vm().count("project-name")) 68 : { 69 0 : error("--manifest-url and --project-name can't be specified at the same time"); 70 0 : return -1; 71 : } 72 14 : else if ((get_vm().count("manifest-url") == 0) && (get_vm().count("project-name") == 0)) 73 : { 74 1 : error("--manifest-url or --project-name must be specified"); 75 1 : return -1; 76 : } 77 : 78 48 : if (get_vm().count("manifest-url")) get_cmd().set_url(get_vm()["manifest-url"].as<std::string>()); 79 24 : if (get_vm().count("manifest-branch")) get_cmd().set_branch(get_vm()["manifest-branch"].as<std::string>()); 80 24 : if (get_vm().count("manifest-name")) get_cmd().set_manifest_name(get_vm()["manifest-name"].as<std::string>()); 81 24 : if (get_vm().count("project-name")) get_cmd().set_project_name(get_vm()["project-name"].as<std::string>()); 82 26 : if (get_vm().count("rev-set")) get_cmd().set_rev_set(get_vm()["rev-set"].as<std::string>()); 83 24 : if (get_vm()["strict"].as<bool>()) get_cmd().set_parse_mode(manifest::ParseMode::Strict); 84 24 : get_cmd().set_google_manifest(get_vm()["google"].as<bool>()); 85 24 : get_cmd().set_git_super_project(get_vm()["git-super"].as<bool>()); 86 : 87 12 : return 0; 88 : } 89 : 90 1 : int CmdInit::print_doc(std::ostream &os) 91 : { 92 1 : os << cmdinit_doc_strings; 93 1 : return 0; 94 : } 95 : 96 : } // namespace esys::repo::cli