Line data Source code
1 : /*! 2 : * \file esys/repo/cli/cmdlist_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/cmdlist.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/cmdlist_doc.cpp" 33 : 34 19 : CmdList::CmdList(AppBase *app) 35 38 : : BaseType(app, "list", "List projects and their associated directories") 36 : { 37 19 : } 38 : 39 19 : CmdList::~CmdList() = default; 40 : 41 5 : std::shared_ptr<po::options_description> CmdList::get_desc() 42 : { 43 5 : auto desc = Cmd::get_desc(); 44 5 : if (desc != nullptr) return desc; 45 : 46 5 : desc = std::make_shared<po::options_description>("List options"); 47 : // clang-format off 48 5 : desc->add_options() 49 5 : ("help,h", "produce help message") 50 5 : ("fullpath,f", po::value<bool>()->default_value(false)->implicit_value(true), 51 : "Display the full work tree path instead of the" 52 : "relative path") 53 5 : ("name-only,n", po::value<bool>()->default_value(false)->implicit_value(true), "Display only the name of the repository") 54 5 : ("path-only,p", po::value<bool>()->default_value(false)->implicit_value(true), "Display only the path of the repository") 55 5 : ("json,j", po::value<std::string>()->implicit_value(""), 56 : "Print versioned JSON (schema esysrepo.list); " 57 : "optional =PATH writes to that file (default: stdout)") 58 : ; 59 : // clang-format on 60 10 : Cmd::set_desc(desc); 61 5 : return desc; 62 0 : } 63 : 64 7 : int CmdList::configure_cmd(CmdType &cmd) 65 : { 66 14 : if (get_vm()["fullpath"].as<bool>()) cmd.set_fullpath(true); 67 14 : if (get_vm()["name-only"].as<bool>()) cmd.set_name_only(true); 68 14 : if (get_vm()["path-only"].as<bool>()) cmd.set_path_only(true); 69 14 : if (get_vm().count("json") > 0) 70 : { 71 2 : cmd.set_json(true); 72 4 : const auto &path = get_vm()["json"].as<std::string>(); 73 2 : if (!path.empty()) cmd.set_json_path(path); 74 : } 75 : 76 7 : return 0; 77 : } 78 : 79 0 : int CmdList::print_doc(std::ostream &os) 80 : { 81 0 : os << cmdlist_doc_strings; 82 0 : return 0; 83 : } 84 : 85 : } // namespace esys::repo::cli