Line data Source code
1 : /*! 2 : * \file esys/repo/cli/cmdpin_cli.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2026 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/cmdpin.h" 20 : 21 : #include <esys/md/rend/styled_string.h> 22 : 23 : #include <termcolor/termcolor.hpp> 24 : 25 : #include <vector> 26 : 27 : namespace esys::repo::cli 28 : { 29 : 30 : #include "esys/repo/cli/cmdpin_doc.cpp" 31 : 32 20 : CmdPin::CmdPin(AppBase *app) 33 40 : : BaseType(app, "pin", "Pin a workspace repository revision (identity-based)") 34 : { 35 20 : } 36 : 37 20 : CmdPin::~CmdPin() = default; 38 : 39 4 : std::shared_ptr<po::options_description> CmdPin::get_desc() 40 : { 41 4 : auto desc = Cmd::get_desc(); 42 4 : if (desc != nullptr) return desc; 43 : 44 4 : desc = std::make_shared<po::options_description>("Pin options"); 45 : // clang-format off 46 4 : desc->add_options() 47 4 : ("help,h", "produce help message") 48 4 : ("name", po::value<std::string>(), "manifest repository name") 49 4 : ("project", po::value<std::string>(), "forge project path (e.g. CI_PROJECT_PATH)") 50 4 : ("url", po::value<std::string>(), "repository clone URL") 51 4 : ("rev", po::value<std::string>(), "revision to pin (required unless --ci / --list / --clear show)") 52 4 : ("ci", po::value<bool>()->default_value(false)->implicit_value(true), 53 : "detect identity and revision from CI environment") 54 4 : ("list", po::value<bool>()->default_value(false)->implicit_value(true), "list all pins") 55 4 : ("clear", po::value<bool>()->default_value(false)->implicit_value(true), "clear a pin") 56 4 : ("rev-set", po::value<std::string>(), "native manifest revision-set name") 57 : ; 58 : // clang-format on 59 8 : Cmd::set_desc(desc); 60 4 : return desc; 61 0 : } 62 : 63 4 : int CmdPin::configure_cmd(CmdType &cmd) 64 : { 65 10 : if (get_vm().count("name")) cmd.set_name(get_vm()["name"].as<std::string>()); 66 10 : if (get_vm().count("project")) cmd.set_project(get_vm()["project"].as<std::string>()); 67 8 : if (get_vm().count("url")) cmd.set_url(get_vm()["url"].as<std::string>()); 68 10 : if (get_vm().count("rev")) cmd.set_rev(get_vm()["rev"].as<std::string>()); 69 12 : if (get_vm()["ci"].as<bool>()) cmd.set_ci(true); 70 8 : if (get_vm()["list"].as<bool>()) cmd.set_list(true); 71 8 : if (get_vm()["clear"].as<bool>()) cmd.set_clear(true); 72 8 : if (get_vm().count("rev-set")) cmd.set_rev_set(get_vm()["rev-set"].as<std::string>()); 73 4 : return 0; 74 : } 75 : 76 0 : int CmdPin::print_doc(std::ostream &os) 77 : { 78 0 : os << cmdpin_doc_strings; 79 0 : return 0; 80 : } 81 : 82 : } // namespace esys::repo::cli