Line data Source code
1 : // DUNE DAQ modification notice:
2 : // This file has been modified from the original ATLAS oks source for the DUNE DAQ project.
3 : // Fork baseline commit: oks-08-03-04 (2022-04-14).
4 : // Renamed since fork: yes (from bin/oks_clone_repository.cpp to apps/oks_clone_repository.cxx).
5 :
6 : /**
7 : * \file oks_clone_repository.cpp
8 : *
9 : * This file is part of the OKS package.
10 : * Author: <Igor.Soloviev@cern.ch>
11 : */
12 :
13 : #include "oks/kernel.hpp"
14 :
15 : #include <stdlib.h>
16 : #include <string.h>
17 :
18 : #include <boost/program_options.hpp>
19 :
20 : using namespace dunedaq::oks;
21 :
22 : int
23 0 : main(int argc, char** argv)
24 : {
25 0 : std::string config_version, user_dir, branch_name;
26 0 : bool verbose = false;
27 :
28 0 : try {
29 0 : boost::program_options::options_description desc(
30 : "Clone and checkout oks repository.\n\n"
31 : "By default the master branch is checkout. The \"branch\" command line option can be used to specify particular "
32 : "one. A branch will be created, if does not exist yet.\n"
33 : "TDAQ_DB_VERSION process environment variable or \"version\" command line option can be used to specify "
34 : "particular version.\n"
35 : "The output directory can be specified via command line, otherwise temporal directory will be created and its "
36 : "name will be reported.\n"
37 : "If TDAQ_DB_USER_REPOSITORY process environment variable is set, the utility makes no effect.\n\n"
38 0 : "The command line options are");
39 :
40 0 : std::vector<std::string> app_types_list;
41 0 : std::vector<std::string> segments_list;
42 :
43 0 : desc.add_options()(
44 0 : "branch,b", boost::program_options::value<std::string>(&branch_name), "checkout or create given branch name")(
45 : "version,e",
46 0 : boost::program_options::value<std::string>(&config_version),
47 0 : "oks config version in type:value format, where type is \"hash\", \"date\" or \"tag\"")(
48 : "output-directory,o",
49 0 : boost::program_options::value<std::string>(&user_dir),
50 0 : "output directory; if not defined, create temporal")("verbose,v",
51 0 : "print verbose information")("help,h", "print help message");
52 :
53 0 : boost::program_options::variables_map vm;
54 0 : boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
55 :
56 0 : if (vm.count("help")) {
57 0 : std::cout << desc << std::endl;
58 0 : return EXIT_SUCCESS;
59 : }
60 :
61 0 : if (vm.count("verbose"))
62 0 : verbose = true;
63 :
64 0 : boost::program_options::notify(vm);
65 0 : } catch (std::exception& ex) {
66 0 : std::cerr << "Command line parsing errors occurred:\n" << ex.what() << std::endl;
67 0 : return EXIT_FAILURE;
68 0 : }
69 :
70 0 : if (!getenv("TDAQ_DB_USER_REPOSITORY")) {
71 0 : if (!user_dir.empty())
72 0 : setenv("TDAQ_DB_USER_REPOSITORY_PATH", user_dir.c_str(), 1);
73 :
74 0 : OksKernel k(user_dir.empty() && !verbose,
75 : verbose,
76 : false,
77 : true,
78 0 : config_version.empty() ? nullptr : config_version.c_str(),
79 0 : branch_name);
80 :
81 0 : if (!k.get_user_repository_root().empty()) {
82 0 : k.unset_repository_created();
83 :
84 0 : if (user_dir.empty())
85 0 : std::cout << k.get_user_repository_root() << std::endl;
86 : }
87 0 : }
88 :
89 : return EXIT_SUCCESS;
90 0 : }
|