Line data Source code
1 : /*! 2 : * \file esys/repo/cli/cmdsync_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/cmdsync.h" 20 : #include "esys/repo/githelper.h" 21 : 22 : #include <msword2md/cpp/string.h> 23 : 24 : #include <termcolor/termcolor.hpp> 25 : 26 : #include <boost/filesystem.hpp> 27 : 28 : #include <vector> 29 : 30 : namespace esys::repo::cli 31 : { 32 : 33 : #include "esys/repo/cli/cmdsync_doc.cpp" 34 : 35 17 : CmdSync::CmdSync(AppBase *app) 36 34 : : BaseType(app, "sync", "Update working tree to the latest revision") 37 : { 38 17 : } 39 : 40 17 : CmdSync::~CmdSync() = default; 41 : 42 3 : std::shared_ptr<po::options_description> CmdSync::get_desc() 43 : { 44 3 : auto desc = Cmd::get_desc(); 45 3 : if (desc != nullptr) return desc; 46 : 47 3 : desc = std::make_shared<po::options_description>("Sync options"); 48 : // clang-format off 49 3 : desc->add_options() 50 3 : ("force-sync", po::value<bool>()->default_value(false)->implicit_value(true), 51 : "overwrite an existing git directory if it needs to" 52 : "point to a different object directory. WARNING: this" 53 : "may cause loss of data") 54 3 : ("job,j", po::value<int>()->default_value(1), "projects to fetch simultaneously (default 1)") 55 3 : ("groups,g", po::value<std::string>(), "the groups to synchronize") 56 3 : ("branch,b", po::value<std::string>(), "the branch to synchronize across repos") 57 3 : ("alt,a", "use alternative address for git repos") 58 3 : ("multi,m", "use captured branches for changes spanning multiple repositories") 59 3 : ("tui", "fullscreen Compact RepoSync progress dashboard (TTY; requires FTXUI build)") 60 3 : ("tui-demo", "like --tui, plus a timed on-screen Tab hint (also ESYSREPO_TUI_DEMO=1)") 61 3 : ("phase-timing", "log per-repo GitHelper phase timings (ms); overrides ESYSREPO_SYNC_PHASE_TIMING") 62 3 : ("no-phase-timing", "disable phase timing logs even if ESYSREPO_SYNC_PHASE_TIMING is set") 63 : ; 64 : // clang-format on 65 6 : Cmd::set_desc(desc); 66 3 : return desc; 67 0 : } 68 : 69 6 : int CmdSync::configure_cmd(CmdType &cmd) 70 : { 71 24 : if (get_vm().count("job")) cmd.set_job_count(get_vm()["job"].as<int>()); 72 6 : cmd.set_sub_args(get_sub_args()); 73 12 : if (get_vm().count("groups")) 74 : { 75 0 : std::vector<std::string> groups; 76 : 77 0 : int result = groups_str_to_groups(get_vm()["groups"].as<std::string>(), groups); 78 0 : if (result < 0) 79 : { 80 0 : return -1; 81 : } 82 0 : cmd.set_groups(groups); 83 0 : } 84 12 : if (get_vm().count("branch")) cmd.set_branch(get_vm()["branch"].as<std::string>()); 85 12 : if (get_vm().count("multi")) cmd.set_multi(true); 86 12 : if (get_vm().count("tui")) cmd.set_tui(true); 87 12 : if (get_vm().count("tui-demo")) cmd.set_tui_demo(true); 88 12 : if (get_vm().count("phase-timing")) GitHelper::set_phase_timing(true); 89 12 : if (get_vm().count("no-phase-timing")) GitHelper::set_phase_timing(false); 90 : 91 : return 0; 92 : } 93 : 94 1 : int CmdSync::print_doc(std::ostream &os) 95 : { 96 1 : os << cmdsync_doc_strings; 97 1 : return 0; 98 : } 99 : 100 : } // namespace esys::repo::cli