76main(
int argc,
char* argv[])
78 const std::string any(
"*");
79 std::string db_name, class_name, object_id, since, until;
83 bool skip_irrelevant =
true;
86 bool direct_info =
false;
87 bool objects_details =
false;
88 bool contained_in =
false;
89 bool referenced_by =
false;
91 boost::program_options::options_description desc(
"Dumps class and objects descriptions using abstract conffwk API.\n"
92 "Without -c or -o options, the utility lists all classes.\n"
97 std::vector<std::string> vesrions_str;
98 std::string class_name2;
100 desc.add_options()(
"database,d",
101 boost::program_options::value<std::string>(&db_name)->required(),
102 "database specification in format plugin-name:parameters")(
103 "changes,a",
"print details of new repository versions or modified files")(
105 boost::program_options::value<std::vector<std::string>>(&vesrions_str)->multitoken()->zero_tokens(),
106 "print details of versions from archive providing 4 parameters \"all|skip\" \"date|id|tag\" \"since\" \"until\"")(
107 "class-direct-info,c",
108 boost::program_options::value<std::string>(&class_name)->default_value(
"")->implicit_value(any),
109 "print direct properties of all classes, or given class if name is provided")(
111 boost::program_options::value<std::string>(&class_name2)->default_value(
"")->implicit_value(any),
112 "similar to -c, but prints all properties of class (all attributes, all superclasses, etc.)")(
113 "list-objects,o",
"list objects of class")(
"print-referenced-by,r",
114 "print objects referencing given object (only with -o option)")(
116 boost::program_options::value<std::string>(&object_id)->default_value(
"")->implicit_value(any),
117 "dump all objects of class or details of given object, if id is provided (-c is required)")(
118 "show-contained-in,n",
"when dump an object, print out the database file it belongs to")(
"help,h",
119 "print help message");
121 boost::program_options::variables_map vm;
122 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
124 if (vm.count(
"help")) {
125 std::cout << desc << std::endl;
129 boost::program_options::notify(vm);
131 if (!class_name.empty())
134 if (!class_name2.empty()) {
135 if (!class_name.empty())
136 throw std::runtime_error(
"cannot use -c and -C options simultaneously");
138 class_name = std::move(class_name2);
141 if (vm.count(
"changes"))
144 if (!vesrions_str.empty()) {
145 if (vesrions_str.size() != 4) {
146 throw std::runtime_error(
"-v option must have 4 parameters, see help");
148 if (vesrions_str[0] ==
"all")
149 skip_irrelevant =
false;
150 else if (vesrions_str[0] !=
"skip")
151 throw std::runtime_error(
"first parameter of -v has to be \"all\" or \"skip\"");
153 if (vesrions_str[1] ==
"date")
155 else if (vesrions_str[1] ==
"id")
157 else if (vesrions_str[1] !=
"tag")
158 throw std::runtime_error(
"second versions parameter must be \"date\", \"id\" or \"tag\"");
160 since = vesrions_str[2];
161 until = vesrions_str[3];
165 if (!object_id.empty())
166 objects_details =
true;
168 if (vm.count(
"list-objects")) {
169 objects_details =
false;
173 if (vm.count(
"print-referenced-by"))
174 referenced_by =
true;
176 if (vm.count(
"show-contained-in"))
179 if (class_name.empty() && !object_id.empty() && object_id != any)
180 throw std::runtime_error(
"object id is set, but no class name given (use -c option)");
181 }
catch (std::exception& ex) {
191 std::cout <<
"Changes:\n";
196 if (!since.empty()) {
197 std::cout <<
"Versions:\n";
202 std::set<std::string> classes;
204 if (!class_name.empty() && class_name != any)
205 classes.insert(class_name);
208 classes.insert(*i.first);
211 if (class_name.empty() && object_id.empty()) {
212 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
213 for (
const auto& i : classes)
214 std::cout <<
" - \'" << i <<
"\'\n";
219 if (!class_name.empty() && object_id.empty()) {
220 if (class_name == any)
221 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
223 for (
const auto& i : classes)
229 const char* prefix =
"";
230 const char* prefix2 =
" ";
231 const char* prefix3 =
" ";
234 if (object_id == any) {
235 if (class_name.empty() || class_name == any) {
236 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
242 for (std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i) {
243 std::vector<ConfigObject> objects;
244 conf.
get(*i, objects);
245 if (objects.empty()) {
246 std::cout << prefix <<
"The class \'" << *i <<
"\' has no objects\n";
248 std::cout << prefix <<
"The class \'" << *i <<
"\' has " << objects.size()
249 <<
" object(s) including sub-classes:\n";
252 std::set<const ConfigObject*, SortByName> sorted_by_id;
254 for (
const auto& j : objects)
255 sorted_by_id.insert(&j);
257 for (
const auto& j : sorted_by_id)
258 if (j->class_name() == *i) {
260 j->print_ref(std::cout, conf, prefix2, contained_in);
262 std::cout << prefix <<
" - \'" << j->UID() <<
"\'\n";
267 std::cout << prefix <<
" - \'" << j->UID() <<
"\' (database class name = \'" << j->class_name()
274 conf.
get(class_name, object_id,
obj);
275 obj.print_ref(std::cout, conf,
"", contained_in);
279 }
catch (dunedaq::conffwk::Exception& ex) {
void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get object by class name and object id (multi-thread safe).
std::vector< dunedaq::conffwk::Version > get_versions(const std::string &since, const std::string &until, dunedaq::conffwk::Version::QueryType type=dunedaq::conffwk::Version::query_by_date, bool skip_irrelevant=true)
Get repository versions in interval.