modules now can access config entries in a new conf.d dir pulled by DPM core (ini file format)
This commit is contained in:
@@ -1,11 +1,40 @@
|
||||
// info.cpp
|
||||
/**
|
||||
* @file info.cpp
|
||||
* @brief Example DPM info module implementation
|
||||
*
|
||||
* Implements a simple DPM module that provides information about the DPM system.
|
||||
* This module demonstrates how to implement the required module interface and
|
||||
* interact with the DPM core through configuration functions.
|
||||
*
|
||||
* @copyright Copyright (c) 2025 SILO GROUP LLC
|
||||
* @author Chris Punches <chris.punches@silogroup.org>
|
||||
*
|
||||
* Part of the Dark Horse Linux Package Manager (DPM)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For bug reports or contributions, please contact the dhlp-contributors
|
||||
* mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
// Declaration of the DPM core function we want to call
|
||||
extern "C" int dpm_core_callback(const char* action, const char* data);
|
||||
// Declaration of the DPM config function we want to call
|
||||
extern "C" const char* dpm_get_config(const char* section, const char* key);
|
||||
|
||||
// Implementation of the info module
|
||||
// This module provides information about the DPM system
|
||||
@@ -29,9 +58,8 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
||||
std::cout << "Available commands:\n";
|
||||
std::cout << " version - Display DPM version information\n";
|
||||
std::cout << " system - Display system information\n";
|
||||
std::cout << " config - Display configuration information\n";
|
||||
std::cout << " help - Display this help message\n";
|
||||
|
||||
dpm_core_callback("log", "No command specified, displayed help");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -39,18 +67,14 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
||||
std::string cmd(command);
|
||||
|
||||
if (cmd == "version") {
|
||||
dpm_core_callback("log", "Executing 'version' command");
|
||||
|
||||
std::cout << "DPM Version: 0.1.0\n";
|
||||
std::cout << "Build Date: " << __DATE__ << "\n";
|
||||
std::cout << "Build Time: " << __TIME__ << "\n";
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == "system") {
|
||||
dpm_core_callback("log", "Executing 'system' command");
|
||||
|
||||
// Request config information
|
||||
dpm_core_callback("get_config", "system.arch");
|
||||
// Request config information using the direct method
|
||||
const char* module_path = dpm_get_config("modules", "module_path");
|
||||
|
||||
std::cout << "System Information:\n";
|
||||
std::cout << " OS: "
|
||||
@@ -77,24 +101,29 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
||||
"Unknown"
|
||||
#endif
|
||||
<< "\n";
|
||||
std::cout << " Module Path: " << (module_path ? module_path : "Not configured") << "\n";
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == "config") {
|
||||
// Retrieve module path configuration
|
||||
const char* module_path = dpm_get_config("modules", "module_path");
|
||||
|
||||
std::cout << "Configuration Information:\n";
|
||||
std::cout << " Module Path: " << (module_path ? module_path : "Not configured") << "\n";
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == "help") {
|
||||
dpm_core_callback("log", "Executing 'help' command");
|
||||
|
||||
std::cout << "DPM Info Module - Provides information about the DPM system\n";
|
||||
std::cout << "Available commands:\n";
|
||||
std::cout << " version - Display DPM version information\n";
|
||||
std::cout << " system - Display system information\n";
|
||||
std::cout << " config - Display configuration information\n";
|
||||
std::cout << " help - Display this help message\n";
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
std::string error_msg = "Unknown command: " + cmd;
|
||||
dpm_core_callback("log", error_msg.c_str());
|
||||
|
||||
std::cerr << "Unknown command: " << cmd << "\n";
|
||||
std::cerr << "Run 'dpm info help' for a list of available commands\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user