24 {
25 enum Exitcode : int {SUCCESS, BADCMD, NOFILE, LOADFAIL, BADRELATIONSHIP};
26
27 CLI::App app{"Check consistency of OKS schema file\n"+
28 fmt::format("Return codes: {} Success, file is OK\n", Exitcode::SUCCESS)+
29 fmt::format(" {} Bad command line\n", Exitcode::BADCMD)+
30 fmt::format(" {} Failed to find file\n", Exitcode::NOFILE)+
31 fmt::format(" {} Failed to load file -- invalid schema\n", Exitcode::LOADFAIL)+
32 fmt::format(" {} File contains relationship to non loaded class\n", Exitcode::BADRELATIONSHIP)
33 };
34
36 app.add_option(
"-f,--file",
filename,
"Schema file")
37 ->required();
38
39 CLI11_PARSE(app, argc, argv);
40
42 try {
44 if (file == nullptr) {
46 return Exitcode::LOADFAIL;
47 }
48 }
51 return Exitcode::LOADFAIL;
52 }
55 return Exitcode::NOFILE;
56 }
57 catch (std::exception& exc) {
58 TLOG() << exc.what() <<
"\n";
59 return Exitcode::LOADFAIL;
60 }
61
62 for (
auto [name, oks_class] : kernel.
classes()) {
63 auto relationships = oks_class->direct_relationships();
64 if (relationships != nullptr) {
65 for (auto rel: *relationships) {
66 auto rel_class = rel->get_class_type();
67 if (rel_class == nullptr) {
68 TLOG() <<
"Error class '" << name
69 << "' has relationship '" << rel->get_name()
70 << "' to a class '" << rel->get_type()
71 << "' that is not loaded\n";
72 return Exitcode::BADRELATIONSHIP;
73 }
74 }
75 }
76
77
78 }
79
80 return 0;
81}
Provides interface to the OKS kernel.
OksFile * load_file(const std::string &name, bool bind=true)
Load OKS database file.
const OksClass::Map & classes() const
Get classes.
virtual const char * what() const noexcept