76int main(
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(
92 "Dumps class and objects descriptions using abstract conffwk API.\n"
93 "Without -c or -o options, the utility lists all classes.\n"
99 std::vector<std::string> vesrions_str;
100 std::string class_name2;
105 boost::program_options::value<std::string>(&db_name)->required(),
106 "database specification in format plugin-name:parameters"
110 "print details of new repository versions or modified files"
114 boost::program_options::value<std::vector<std::string>>(&vesrions_str)->multitoken()->zero_tokens(),
115 "print details of versions from archive providing 4 parameters \"all|skip\" \"date|id|tag\" \"since\" \"until\""
118 "class-direct-info,c",
119 boost::program_options::value<std::string>(&class_name)->default_value(
"")->implicit_value(any),
120 "print direct properties of all classes, or given class if name is provided"
124 boost::program_options::value<std::string>(&class_name2)->default_value(
"")->implicit_value(any),
125 "similar to -c, but prints all properties of class (all attributes, all superclasses, etc.)"
129 "list objects of class"
132 "print-referenced-by,r",
133 "print objects referencing given object (only with -o option)"
137 boost::program_options::value<std::string>(&object_id)->default_value(
"")->implicit_value(any),
138 "dump all objects of class or details of given object, if id is provided (-c is required)"
141 "show-contained-in,n",
142 "when dump an object, print out the database file it belongs to"
149 boost::program_options::variables_map vm;
150 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
152 if (vm.count(
"help"))
154 std::cout << desc << std::endl;
158 boost::program_options::notify(vm);
160 if (!class_name.empty())
163 if (!class_name2.empty())
165 if (!class_name.empty())
166 throw std::runtime_error(
"cannot use -c and -C options simultaneously");
168 class_name = std::move(class_name2);
171 if (vm.count(
"changes"))
174 if (!vesrions_str.empty())
176 if (vesrions_str.size() != 4)
178 throw std::runtime_error(
"-v option must have 4 parameters, see help");
182 if (vesrions_str[0] ==
"all")
183 skip_irrelevant =
false;
184 else if (vesrions_str[0] !=
"skip")
185 throw std::runtime_error(
"first parameter of -v has to be \"all\" or \"skip\"");
187 if (vesrions_str[1] ==
"date")
189 else if (vesrions_str[1] ==
"id")
191 else if (vesrions_str[1] !=
"tag")
192 throw std::runtime_error(
"second versions parameter must be \"date\", \"id\" or \"tag\"");
194 since = vesrions_str[2];
195 until = vesrions_str[3];
199 if (!object_id.empty())
200 objects_details =
true;
202 if (vm.count(
"list-objects"))
204 objects_details =
false;
208 if (vm.count(
"print-referenced-by"))
209 referenced_by =
true;
211 if (vm.count(
"show-contained-in"))
214 if (class_name.empty() && !object_id.empty() && object_id != any)
215 throw std::runtime_error(
"object id is set, but no class name given (use -c option)");
217 catch (std::exception &ex)
231 std::cout <<
"Changes:\n";
238 std::cout <<
"Versions:\n";
243 std::set<std::string> classes;
245 if (!class_name.empty() && class_name != any)
246 classes.insert(class_name);
249 classes.insert(*i.first);
252 if (class_name.empty() && object_id.empty())
254 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
255 for (
const auto &i : classes)
256 std::cout <<
" - \'" << i <<
"\'\n";
261 if (!class_name.empty() && object_id.empty())
263 if (class_name == any)
264 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
266 for (
const auto &i : classes)
272 const char *prefix =
"";
273 const char *prefix2 =
" ";
274 const char *prefix3 =
" ";
277 if (object_id == any)
279 if (class_name.empty() || class_name == any)
281 std::cout <<
"The database schema has " << classes.size() <<
" class(es):\n";
287 for (std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i)
289 std::vector<ConfigObject> objects;
290 conf.
get(*i, objects);
293 std::cout << prefix <<
"The class \'" << *i <<
"\' has no objects\n";
297 std::cout << prefix <<
"The class \'" << *i <<
"\' has " << objects.size() <<
" object(s) including sub-classes:\n";
300 std::set<const ConfigObject*, SortByName> sorted_by_id;
302 for (
const auto &j : objects)
303 sorted_by_id.insert(&j);
305 for (
const auto &j : sorted_by_id)
306 if (j->class_name() == *i)
309 j->print_ref(std::cout, conf, prefix2, contained_in);
311 std::cout << prefix <<
" - \'" << j->UID() <<
"\'\n";
318 std::cout << prefix <<
" - \'" << j->UID() <<
"\' (database class name = \'" << j->class_name() <<
"\')\n";
326 conf.
get(class_name, object_id, obj);
327 obj.print_ref(std::cout, conf,
"", contained_in);
332 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.