84{
85 const std::string any("*");
86 std::string db_name, class_name, object_id, since, until;
87
88 bool changes = false;
89
90 bool skip_irrelevant = true;
92
93 bool direct_info = false;
94 bool objects_details = false;
95 bool contained_in = false;
96 bool referenced_by = false;
97
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"
101 "\n"
102 "Options/Arguments");
103
104 try
105 {
106 std::vector<std::string> vesrions_str;
107 std::string class_name2;
108
109 desc.add_options()
110 (
111 "database,d",
112 boost::program_options::value<std::string>(&db_name)->required(),
113 "database specification in format plugin-name:parameters"
114 )
115 (
116 "changes,a",
117 "print details of new repository versions or modified files"
118 )
119 (
120 "versions,v",
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\""
123 )
124 (
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"
128 )
129 (
130 "class-all-info,C",
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.)"
133 )
134 (
135 "list-objects,o",
136 "list objects of class"
137 )
138 (
139 "print-referenced-by,r",
140 "print objects referencing given object (only with -o option)"
141 )
142 (
143 "dump-objects,O",
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)"
146 )
147 (
148 "show-contained-in,n",
149 "when dump an object, print out the database file it belongs to"
150 )
151 (
152 "help,h",
153 "print help message"
154 );
155
156 boost::program_options::variables_map vm;
157 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
158
159 if (vm.count("help"))
160 {
161 std::cout << desc << std::endl;
162 return EXIT_SUCCESS;
163 }
164
165 boost::program_options::notify(vm);
166
167 if (!class_name.empty())
168 direct_info = true;
169
170 if (!class_name2.empty())
171 {
172 if (!class_name.empty())
173 throw std::runtime_error("cannot use -c and -C options simultaneously");
174 else
175 class_name = std::move(class_name2);
176 }
177
178 if (vm.count("changes"))
179 changes = true;
180
181 if (!vesrions_str.empty())
182 {
183 if (vesrions_str.size() != 4)
184 {
185 throw std::runtime_error("-v option must have 4 parameters, see help");
186 }
187 else
188 {
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\"");
193
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\"");
200
201 since = vesrions_str[2];
202 until = vesrions_str[3];
203 }
204 }
205
206 if (!object_id.empty())
207 objects_details = true;
208
209 if (vm.count("list-objects"))
210 {
211 objects_details = false;
212 object_id = any;
213 }
214
215 if (vm.count("print-referenced-by"))
216 referenced_by = true;
217
218 if (vm.count("show-contained-in"))
219 contained_in = true;
220
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)");
223 }
224 catch (std::exception &ex)
225 {
227 return EXIT_FAILURE;
228 }
229
230
231 try
232 {
234
235
236 if (changes)
237 {
238 std::cout << "Changes:\n";
240 return EXIT_SUCCESS;
241 }
242
243 if (!since.empty())
244 {
245 std::cout << "Versions:\n";
246 print_versions(conf.get_versions(since, until, query_type, skip_irrelevant));
247 return EXIT_SUCCESS;
248 }
249
250 std::set<std::string> classes;
251
252 if (!class_name.empty() && class_name != any)
253 classes.insert(class_name);
254 else
255 for (const auto &i : conf.superclasses())
256 classes.insert(*i.first);
257
258
259 if (class_name.empty() && object_id.empty())
260 {
261 std::cout << "The database schema has " << classes.size() << " class(es):\n";
262 for (const auto &i : classes)
263 std::cout << " - \'" << i << "\'\n";
264 return EXIT_SUCCESS;
265 }
266
267
268 if (!class_name.empty() && object_id.empty())
269 {
270 if (class_name == any)
271 std::cout << "The database schema has " << classes.size() << " class(es):\n";
272
273 for (const auto &i : classes)
274 conf.get_class_info(i, direct_info).print(std::cout, " ");
275
276 return EXIT_SUCCESS;
277 }
278
279 const char *prefix = "";
280 const char *prefix2 = " ";
281 const char *prefix3 = " ";
282
283
284 if (object_id == any)
285 {
286 if (class_name.empty() || class_name == any)
287 {
288 std::cout << "The database schema has " << classes.size() << " class(es):\n";
289 prefix = " ";
290 prefix2 = " ";
291 prefix3 = " ";
292 }
293
294 for (std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i)
295 {
296 std::vector<ConfigObject> objects;
297 conf.get(*i, objects);
298 if (objects.empty())
299 {
300 std::cout << prefix << "The class \'" << *i << "\' has no objects\n";
301 }
302 else
303 {
304 std::cout << prefix << "The class \'" << *i << "\' has " << objects.size() << " object(s) including sub-classes:\n";
305
306
307 std::set<const ConfigObject*, SortByName> sorted_by_id;
308
309 for (const auto &j : objects)
310 sorted_by_id.insert(&j);
311
312 for (const auto &j : sorted_by_id)
313 if (j->class_name() == *i)
314 {
315 if (objects_details)
316 j->print_ref(std::cout, conf, prefix2, contained_in);
317 else
318 std::cout << prefix << " - \'" << j->UID() << "\'\n";
319
320 if (referenced_by)
322 }
323 else
324 {
325 std::cout << prefix << " - \'" << j->UID() << "\' (database class name = \'" << j->class_name() << "\')\n";
326 }
327 }
328 }
329 }
330 else
331 {
333 conf.get(class_name, object_id, obj);
334 obj.print_ref(std::cout, conf,
"", contained_in);
335 if (referenced_by)
337 }
338 }
339 catch (dunedaq::conffwk::Exception &ex)
340 {
342 return EXIT_FAILURE;
343 }
344
345 return EXIT_SUCCESS;
346}
Represents database objects.
Defines base class for cache of template objects.
static void print_versions(const std::vector< dunedaq::conffwk::Version > &versions)
static void print_referenced_by(const ConfigObject &obj, const char *prefix)
void fatal(const Issue &issue)