continued restructure for dpmdk and updated default behaviour
parent
f0859c93c3
commit
255debef50
|
@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 20)
|
|||
# Create modules directory
|
||||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/modules)
|
||||
|
||||
# Main DPM executable
|
||||
add_executable(
|
||||
dpm
|
||||
src/dpm.cpp
|
||||
|
@ -19,19 +20,20 @@ add_executable(
|
|||
src/Logger.cpp
|
||||
)
|
||||
|
||||
# Include directories for the main executable
|
||||
target_include_directories(dpm PRIVATE include)
|
||||
target_link_libraries(dpm dl)
|
||||
|
||||
# Export symbols for dynamic loading
|
||||
target_link_options(dpm PRIVATE -rdynamic)
|
||||
|
||||
# Add the info module with specific source files
|
||||
# Add the info module
|
||||
add_library(info MODULE
|
||||
modules/info/info.cpp
|
||||
modules/info/src/infoFuncs.cpp
|
||||
# DO NOT include dpmdk sources which have different include requirements
|
||||
)
|
||||
|
||||
# Set module properties
|
||||
set_target_properties(
|
||||
info PROPERTIES
|
||||
PREFIX ""
|
||||
|
@ -39,11 +41,12 @@ set_target_properties(
|
|||
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
|
||||
include
|
||||
${CMAKE_SOURCE_DIR} # Add the project root directory to search path
|
||||
modules/info
|
||||
modules/info/include # Add this to find infoFuncs.hpp
|
||||
modules/info/include
|
||||
)
|
||||
|
||||
# Installation rules
|
||||
|
@ -56,7 +59,7 @@ install(
|
|||
PATTERN "*.conf"
|
||||
)
|
||||
|
||||
# Install all .so files from build/modules to the module path
|
||||
# Install modules
|
||||
install(
|
||||
DIRECTORY ${CMAKE_BINARY_DIR}/modules/
|
||||
DESTINATION /usr/lib/dpm/modules
|
||||
|
|
|
@ -76,4 +76,14 @@ int main_check_module_path(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
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* @file dpm_interface_helpers.hpp
|
||||
* @file dpm_interface_helpers.hpp
|
||||
* @brief Helper functions for DPM command-line interface
|
||||
*
|
||||
* 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 module_name; /**< Name of the module to execute */
|
||||
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
|
||||
* 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.
|
||||
*
|
||||
* @param argc Number of command-line arguments
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <sys/utsname.h>
|
||||
#include "dpmdk/include/CommonModuleAPI.hpp"
|
||||
#include <dpmdk/include/CommonModuleAPI.hpp>
|
||||
|
||||
/**
|
||||
* @enum Command
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include <fstream>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "dpmdk/include/CommonModuleAPI.hpp"
|
||||
#include "include/infoFuncs.hpp"
|
||||
|
||||
/**
|
||||
|
|
28
src/dpm.cpp
28
src/dpm.cpp
|
@ -48,9 +48,10 @@
|
|||
// the default behaviour if dpm is executed without being told to do anything
|
||||
int default_behavior(const ModuleLoader& loader)
|
||||
{
|
||||
return main_list_modules(loader);
|
||||
return main_show_help();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Entry point for the DPM utility
|
||||
*
|
||||
|
@ -131,24 +132,33 @@ int main( int argc, char* argv[] )
|
|||
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
|
||||
// dpm behaviour
|
||||
if ( args.module_name.empty() )
|
||||
{
|
||||
return default_behavior( loader );
|
||||
// behaviour (show help)
|
||||
if (args.module_name.empty()) {
|
||||
return default_behavior(loader);
|
||||
}
|
||||
|
||||
// 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;
|
||||
loader.get_module_path( absolute_modules_path );
|
||||
loader.get_module_path(absolute_modules_path);
|
||||
|
||||
// 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_path = absolute_modules_path.c_str();
|
||||
|
||||
// pair result with a message and exit with the appropriate error code
|
||||
return handle_error(result);
|
||||
}
|
||||
}
|
|
@ -167,3 +167,22 @@ int main_list_modules(const ModuleLoader& loader)
|
|||
|
||||
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;
|
||||
}
|
|
@ -35,31 +35,33 @@ CommandArgs parse_args(int argc, char* argv[])
|
|||
CommandArgs args;
|
||||
args.module_path = "";
|
||||
args.config_dir = "";
|
||||
args.list_modules = false;
|
||||
args.show_help = false;
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"module-path", required_argument, 0, 'm'},
|
||||
{"config-dir", required_argument, 0, 'c'},
|
||||
{"list-modules", no_argument, 0, 'l'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int opt;
|
||||
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) {
|
||||
case 'm':
|
||||
args.module_path = optarg;
|
||||
break;
|
||||
break;
|
||||
case 'c':
|
||||
args.config_dir = optarg;
|
||||
break;
|
||||
break;
|
||||
case 'l':
|
||||
args.list_modules = true;
|
||||
break;
|
||||
case 'h':
|
||||
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"
|
||||
<< " -h, --help Show this help message\n\n";
|
||||
exit(0);
|
||||
args.show_help = true;
|
||||
break;
|
||||
case '?':
|
||||
exit(1);
|
||||
}
|
||||
|
@ -83,4 +85,4 @@ CommandArgs parse_args(int argc, char* argv[])
|
|||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue