fixed a cli arg parsing error

This commit is contained in:
Chris Punches
2025-03-13 23:03:37 -04:00
parent a822bc93e7
commit a924a245df
5 changed files with 63 additions and 24 deletions

View File

@@ -64,7 +64,7 @@ extern "C" const char* dpm_module_get_version(void) {
* @return Const char pointer to the module description string
*/
extern "C" const char* dpm_get_description(void) {
return "DPM Build Module - Creates DPM packages according to specification";
return "Creates DPM packages according to specification.";
}
/**

View File

@@ -1,6 +1,15 @@
#include "cli_parsers.hpp"
int parse_create_options(int argc, char** argv, BuildOptions& options) {
// Check for help flags directly before any other parsing
for (int i = 0; i < argc; i++) {
if (argv[i] && (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "help") == 0)) {
options.show_help = true;
// Skip all other parsing for help flag
return 0;
}
}
// Track which options were explicitly provided on command line
bool output_dir_provided = false;
bool contents_dir_provided = false;
@@ -190,12 +199,16 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) {
return 0;
}
Command parse_command(const char* cmd_str) {
if (cmd_str == nullptr || strlen(cmd_str) == 0) {
return CMD_HELP;
}
// Check for stage command, including when it has additional arguments
if (strncmp(cmd_str, "stage", 5) == 0) {
return CMD_STAGE;
}
// Check if cmd_str is a help option
if (strcmp(cmd_str, "-h") == 0 || strcmp(cmd_str, "--help") == 0) {
return CMD_HELP;
@@ -203,14 +216,16 @@ Command parse_command(const char* cmd_str) {
else if (strcmp(cmd_str, "help") == 0) {
return CMD_HELP;
}
else if (strcmp(cmd_str, "stage") == 0) {
return CMD_STAGE;
}
return CMD_UNKNOWN;
}
int validate_build_options(const BuildOptions& options) {
// Check if help was requested - skip validation in this case
if (options.show_help) {
return 0;
}
// Check if contents directory is provided and exists
if (options.contents_dir.empty()) {
dpm_log(LOG_ERROR, "Contents directory is required (--contents)");

View File

@@ -27,8 +27,6 @@ int cmd_stage(int argc, char** argv) {
// Validate options
int validate_result = validate_build_options(options);
if (validate_result != 0) {
// Show help when validation fails
//cmd_help(argc, argv);
return validate_result;
}

View File

@@ -68,7 +68,7 @@ extern "C" const char* dpm_module_get_version(void) {
* @return Const char pointer to the module description string
*/
extern "C" const char* dpm_get_description(void) {
return "DPM Info Module - Provides information about the DPM system";
return "Provides information about the DPM system.";
}