Line data Source code
1 : /*! 2 : * \file esys/repo/cli/cmddeps_cli.cpp 3 : * \brief CmdDeps CLI for esysrepo (ADR-0022) 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/cmddeps.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/cmddeps_doc.cpp" 31 : 32 20 : CmdDeps::CmdDeps(AppBase *app) 33 40 : : BaseType(app, "deps", "Print the manifest repository depends graph") 34 : { 35 20 : } 36 : 37 20 : CmdDeps::~CmdDeps() = default; 38 : 39 4 : std::shared_ptr<po::options_description> CmdDeps::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>("Deps options"); 45 : // clang-format off 46 4 : desc->add_options() 47 4 : ("help,h", "produce help message") 48 4 : ("json", po::value<bool>()->default_value(false)->implicit_value(true), "print depends graph as JSON") 49 4 : ("dot", po::value<bool>()->default_value(false)->implicit_value(true), "print depends graph as Graphviz DOT") 50 4 : ("mermaid", po::value<bool>()->default_value(false)->implicit_value(true), 51 : "print depends graph as Mermaid (default)") 52 4 : ("link", po::value<bool>()->default_value(false)->implicit_value(true), 53 : "add one session-only edge for this invocation") 54 4 : ("path", po::value<std::vector<std::string>>(), "repository path (use twice with --link)") 55 4 : ("name", po::value<std::vector<std::string>>(), "repository name (use twice with --link)") 56 4 : ("project", po::value<std::vector<std::string>>(), "forge project path (use twice with --link)") 57 4 : ("url", po::value<std::vector<std::string>>(), "repository URL (use twice with --link)") 58 : ; 59 : // clang-format on 60 8 : Cmd::set_desc(desc); 61 4 : return desc; 62 0 : } 63 : 64 4 : int CmdDeps::configure_cmd(CmdType &cmd) 65 : { 66 8 : if (get_vm()["json"].as<bool>()) cmd.set_json(true); 67 8 : if (get_vm()["dot"].as<bool>()) cmd.set_dot(true); 68 8 : if (get_vm()["mermaid"].as<bool>()) cmd.set_mermaid(true); 69 12 : if (get_vm()["link"].as<bool>()) cmd.set_link(true); 70 10 : if (get_vm().count("path")) cmd.set_paths(get_vm()["path"].as<std::vector<std::string>>()); 71 8 : if (get_vm().count("name")) cmd.set_names(get_vm()["name"].as<std::vector<std::string>>()); 72 8 : if (get_vm().count("project")) cmd.set_projects(get_vm()["project"].as<std::vector<std::string>>()); 73 8 : if (get_vm().count("url")) cmd.set_urls(get_vm()["url"].as<std::vector<std::string>>()); 74 4 : return 0; 75 : } 76 : 77 0 : int CmdDeps::print_doc(std::ostream &os) 78 : { 79 0 : os << cmddeps_doc_strings; 80 0 : return 0; 81 : } 82 : 83 : } // namespace esys::repo::cli