continued restructure for dpmdk and updated default behaviour
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user