continued restructure for dpmdk and updated default behaviour

master
Chris Punches 2025-03-08 17:44:23 -05:00
parent f0859c93c3
commit 255debef50
10 changed files with 73 additions and 28 deletions

View File

@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 20)
# Create modules directory # Create modules directory
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/modules) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
# Main DPM executable
add_executable( add_executable(
dpm dpm
src/dpm.cpp src/dpm.cpp
@ -19,19 +20,20 @@ add_executable(
src/Logger.cpp src/Logger.cpp
) )
# Include directories for the main executable
target_include_directories(dpm PRIVATE include) target_include_directories(dpm PRIVATE include)
target_link_libraries(dpm dl) target_link_libraries(dpm dl)
# Export symbols for dynamic loading # Export symbols for dynamic loading
target_link_options(dpm PRIVATE -rdynamic) target_link_options(dpm PRIVATE -rdynamic)
# Add the info module with specific source files # Add the info module
add_library(info MODULE add_library(info MODULE
modules/info/info.cpp modules/info/info.cpp
modules/info/src/infoFuncs.cpp modules/info/src/infoFuncs.cpp
# DO NOT include dpmdk sources which have different include requirements
) )
# Set module properties
set_target_properties( set_target_properties(
info PROPERTIES info PROPERTIES
PREFIX "" PREFIX ""
@ -39,11 +41,12 @@ set_target_properties(
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/modules" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/modules"
) )
# Add include directories for the info module # Include directories for the info module
target_include_directories(info PRIVATE target_include_directories(info PRIVATE
include include
${CMAKE_SOURCE_DIR} # Add the project root directory to search path
modules/info modules/info
modules/info/include # Add this to find infoFuncs.hpp modules/info/include
) )
# Installation rules # Installation rules
@ -56,7 +59,7 @@ install(
PATTERN "*.conf" PATTERN "*.conf"
) )
# Install all .so files from build/modules to the module path # Install modules
install( install(
DIRECTORY ${CMAKE_BINARY_DIR}/modules/ DIRECTORY ${CMAKE_BINARY_DIR}/modules/
DESTINATION /usr/lib/dpm/modules DESTINATION /usr/lib/dpm/modules

View File

@ -76,4 +76,14 @@ int main_check_module_path(const ModuleLoader& loader);
*/ */
int main_list_modules(const ModuleLoader& loader); int main_list_modules(const ModuleLoader& loader);
/**
* @brief Displays usage information for DPM
*
* Shows a help message describing the available command-line options
* and general usage information for the DPM utility.
*
* @return 0 on success
*/
int main_show_help();
/** @} */ // end of dpm_interface group /** @} */ // end of dpm_interface group

View File

@ -1,5 +1,5 @@
/** /**
* @file dpm_interface_helpers.hpp * @file dpm_interface_helpers.hpp
* @brief Helper functions for DPM command-line interface * @brief Helper functions for DPM command-line interface
* *
* Provides utility functions for command-line argument parsing and * Provides utility functions for command-line argument parsing and
@ -51,6 +51,8 @@ struct CommandArgs {
std::string config_dir; /**< Path to the directory containing configuration files */ std::string config_dir; /**< Path to the directory containing configuration files */
std::string module_name; /**< Name of the module to execute */ std::string module_name; /**< Name of the module to execute */
std::string command; /**< Command string to pass to the module */ std::string command; /**< Command string to pass to the module */
bool list_modules; /**< Flag to indicate if modules should be listed */
bool show_help; /**< Flag to indicate if help message should be shown */
}; };
/** /**
@ -58,7 +60,7 @@ struct CommandArgs {
* *
* Processes the arguments provided to DPM and organizes them into a * Processes the arguments provided to DPM and organizes them into a
* CommandArgs structure for easier access. Handles options like * CommandArgs structure for easier access. Handles options like
* --module-path, --config-dir, and --help, as well as module names * --module-path, --config-dir, --list-modules, and --help, as well as module names
* and module-specific arguments. * and module-specific arguments.
* *
* @param argc Number of command-line arguments * @param argc Number of command-line arguments

View File

@ -17,7 +17,7 @@
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <sys/utsname.h> #include <sys/utsname.h>
#include "dpmdk/include/CommonModuleAPI.hpp" #include <dpmdk/include/CommonModuleAPI.hpp>
/** /**
* @enum Command * @enum Command

View File

@ -37,7 +37,6 @@
#include <fstream> #include <fstream>
#include <sys/utsname.h> #include <sys/utsname.h>
#include "dpmdk/include/CommonModuleAPI.hpp"
#include "include/infoFuncs.hpp" #include "include/infoFuncs.hpp"
/** /**

View File

@ -48,9 +48,10 @@
// the default behaviour if dpm is executed without being told to do anything // the default behaviour if dpm is executed without being told to do anything
int default_behavior(const ModuleLoader& loader) int default_behavior(const ModuleLoader& loader)
{ {
return main_list_modules(loader); return main_show_help();
} }
/** /**
* @brief Entry point for the DPM utility * @brief Entry point for the DPM utility
* *
@ -131,21 +132,30 @@ int main( int argc, char* argv[] )
return path_check_result; return path_check_result;
} }
// If help is requested, show it and exit
if (args.show_help) {
return main_show_help();
}
// If list modules is requested, show the list and exit
if (args.list_modules) {
return main_list_modules(loader);
}
// if no module is provided to execute, then trigger the default // if no module is provided to execute, then trigger the default
// dpm behaviour // behaviour (show help)
if ( args.module_name.empty() ) if (args.module_name.empty()) {
{ return default_behavior(loader);
return default_behavior( loader );
} }
// execute the module // execute the module
DPMErrorCategory execute_error = loader.execute_module( args.module_name, args.command ); DPMErrorCategory execute_error = loader.execute_module(args.module_name, args.command);
std::string absolute_modules_path; std::string absolute_modules_path;
loader.get_module_path( absolute_modules_path ); loader.get_module_path(absolute_modules_path);
// construct an error object // construct an error object
FlexDPMError result = make_error( execute_error ); FlexDPMError result = make_error(execute_error);
result.module_name = args.module_name.c_str(); result.module_name = args.module_name.c_str();
result.module_path = absolute_modules_path.c_str(); result.module_path = absolute_modules_path.c_str();

View File

@ -167,3 +167,22 @@ int main_list_modules(const ModuleLoader& loader)
return 0; return 0;
} }
/**
* @brief Displays usage information for DPM
*
* Shows a help message describing the available command-line options
* and general usage information for the DPM utility.
*
* @return 0 on success
*/
int main_show_help() {
std::cout << "Usage: dpm [options] [module-name] [module args...] [module-command] [command-args]\n\n"
<< "Options:\n\n"
<< " -m, --module-path PATH Path to DPM modules (overrides modules.modules_path in config)\n"
<< " -c, --config-dir PATH Path to DPM configuration directory\n"
<< " -l, --list-modules List available modules\n"
<< " -h, --help Show this help message\n\n"
<< "For module-specific help, use: dpm <module-name> help\n\n";
return 0;
}

View File

@ -35,31 +35,33 @@ CommandArgs parse_args(int argc, char* argv[])
CommandArgs args; CommandArgs args;
args.module_path = ""; args.module_path = "";
args.config_dir = ""; args.config_dir = "";
args.list_modules = false;
args.show_help = false;
static struct option long_options[] = { static struct option long_options[] = {
{"module-path", required_argument, 0, 'm'}, {"module-path", required_argument, 0, 'm'},
{"config-dir", required_argument, 0, 'c'}, {"config-dir", required_argument, 0, 'c'},
{"list-modules", no_argument, 0, 'l'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
int opt; int opt;
int option_index = 0; int option_index = 0;
while ((opt = getopt_long(argc, argv, "m:c:h", long_options, &option_index)) != -1) { while ((opt = getopt_long(argc, argv, "m:c:lh", long_options, &option_index)) != -1) {
switch (opt) { switch (opt) {
case 'm': case 'm':
args.module_path = optarg; args.module_path = optarg;
break; break;
case 'c': case 'c':
args.config_dir = optarg; args.config_dir = optarg;
break; break;
case 'l':
args.list_modules = true;
break;
case 'h': case 'h':
std::cout << "Usage: dpm [options] [module-name] [module args...] [module-command] [command-args]\n\n" args.show_help = true;
<< "Options:\n\n" break;
<< " -m, --module-path PATH Path to DPM modules (overrides modules.modules_path in config)\n"
<< " -c, --config-dir PATH Path to DPM configuration directory\n"
<< " -h, --help Show this help message\n\n";
exit(0);
case '?': case '?':
exit(1); exit(1);
} }