diff --git a/src/main.c b/src/main.c index a46fcaf..96629e6 100644 --- a/src/main.c +++ b/src/main.c @@ -47,6 +47,7 @@ int main(int argc, char *argv[]) { free(config_path); bool hit_mod_cmd = false; + bool hit_mod_info = false; for (size_t i = 1; i < (size_t)argc; ++i) { if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) { @@ -106,6 +107,38 @@ int main(int argc, char *argv[]) { } } + if (strcmp(argv[i], "info") == 0 || hit_mod_info) { + // no more args + if (i == (size_t)argc - 1) { + fprintf(stderr, "error: no module passed\n"); + exit(EXIT_FAILURE); + } + + // some other -/-- option in between the info and the module + if (argv[i][0] == '-') { + hit_mod_info = true; + continue; + } + + i += 1; + + for (size_t ii = 0; ii < config.module_count; ++ii) { + Module current_module = config.modules[ii]; + void *handle = dlopen(current_module.path, RTLD_NOW); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" + semver (*mod_version)(void) = dlsym(handle, "version"); + const char *(*mod_name)(void) = dlsym(handle, "name"); +#pragma GCC diagnostic pop + + const char *_mod_name = mod_name(); + if (strcmp(argv[i], _mod_name) != 0) + continue; + + printf("%s-%s\n", _mod_name, svtoa(mod_version())); + } + } + exit(EXIT_SUCCESS); } }