83int main(
int argc,
char *argv[])
85 const std::string any(
"*");
86 std::string db_name, class_name, object_id, since, until;
90 bool skip_irrelevant =
true;
93 bool direct_info =
false;
94 bool objects_details =
false;
95 bool contained_in =
false;
96 bool referenced_by =
false;
98 boost::program_options::options_description desc(
99 "Dumps class and objects descriptions using abstract conffwk API.\n"
100 "Without -c or -o options, the utility lists all classes.\n"
102 "Options/Arguments");
106 std::vector<std::string> vesrions_str;
107 std::string class_name2;
112 boost::program_options::value<std::string>(&db_name)->required(),
113 "database specification in format plugin-name:parameters"
117 "print details of new repository versions or modified files"
121 boost::program_options::value<std::vector<std::string>>(&vesrions_str)->multitoken()->zero_tokens(),
122 "print details of versions from archive providing 4 parameters \"all|skip\" \"date|id|tag\" \"since\" \"until\""
125 "class-direct-info,c",
126 boost::program_options::value<std::string>(&class_name)->default_value(
"")->implicit_value(any),
127 "print direct properties of all classes, or given class if name is provided"
131 boost::program_options::value<std::string>(&class_name2)->default_value(
"")->implicit_value(any),
132 "similar to -c, but prints all properties of class (all attributes, all superclasses, etc.)"
136 "list objects of class"
139 "print-referenced-by,r",
140 "print objects referencing given object (only with -o option)"
144 boost::program_options::value<std::string>(&object_id)->default_value(
"")->implicit_value(any),
145 "dump all objects of class or details of given object, if id is provided (-c is required)"
148 "show-contained-in,n",
149 "when dump an object, print out the database file it belongs to"
156 boost::program_options::variables_map vm;
157 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
159 if (vm.count(
"help"))
161 std::cout << desc << std::endl;
165 boost::program_options::notify(vm);
167 if (!class_name.empty())
170 if (!class_name2.empty())
172 if (!class_name.empty())
173 throw std::runtime_error(
"cannot use -c and -C options simultaneously");
175 class_name = std::move(class_name2);
178 if (vm.count(
"changes"))
181 if (!vesrions_str.empty())
183 if (vesrions_str.size() != 4)
185 throw std::runtime_error(
"-v option must have 4 parameters, see help");
189 if (vesrions_str[0] ==
"all")
190 skip_irrelevant =
false;
191 else if (vesrions_str[0] !=
"skip")
192 throw std::runtime_error(
"first parameter of -v has to be \"all\" or \"skip\"");
194 if (vesrions_str[1] ==
"date")
196 else if (vesrions_str[1] ==
"id")
198 else if (vesrions_str[1] !=
"tag")
199 throw std::runtime_error(
"second versions parameter must be \"date\", \"id\" or \"tag\"");
201 since = vesrions_str[2];
202 until = vesrions_str[3];
206 if (!object_id.empty())
207 objects_details =
true;
209 if (vm.count(
"list-objects"))
211 objects_details =
false;
215 if (vm.count(
"print-referenced-by"))
216 referenced_by =
true;
218 if (vm.count(
"show-contained-in"))
221 if (class_name.empty() && !object_id.empty() && object_id != any)
222 throw std::runtime_error(
"object id is set, but no class name given (use -c option)");
224 catch (std::exception &ex)
238 std::cout <<
"Changes:\n";
245 std::cout <<
"Versions:\n";
250 std::set<std::string> classes;
252 if (!class_name.empty() && class_name != any)
253 classes.insert(class_name);
256 classes.insert(*i.first);
259 if (class_name.empty() && object_id.empty())
261 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
262 for (
const auto &i : classes)
263 std::cout <<
" - \'" << i <<
"\'\n";
268 if (!class_name.empty() && object_id.empty())
270 if (class_name == any)
271 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
273 for (
const auto &i : classes)
279 const char *prefix =
"";
280 const char *prefix2 =
" ";
281 const char *prefix3 =
" ";
284 if (object_id == any)
286 if (class_name.empty() || class_name == any)
288 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
294 for (std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i)
296 std::vector<ConfigObject> objects;
297 conf.
get(*i, objects);
300 std::cout << prefix <<
"The class \'" << *i <<
"\' has no objects\n";
304 std::cout << prefix <<
"The class \'" << *i <<
"\' has " << objects.size() <<
" object(s) including sub-classes:\n";
307 std::set<const ConfigObject*, SortByName> sorted_by_id;
309 for (
const auto &j : objects)
310 sorted_by_id.insert(&j);
312 for (
const auto &j : sorted_by_id)
313 if (j->class_name() == *i)
316 j->print_ref(std::cout, conf, prefix2, contained_in);
318 std::cout << prefix <<
" - \'" << j->UID() <<
"\'\n";
325 std::cout << prefix <<
" - \'" << j->UID() <<
"\' (database class name = \'" << j->class_name() <<
"\')\n";
333 conf.
get(class_name, object_id,
obj);
334 obj.print_ref(std::cout, conf,
"", contained_in);
339 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.