some cleaning up of commandline argument parsing
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
#include "cli_parsers.hpp"
|
||||
|
||||
|
||||
int parse_create_options(int argc, char** argv, BuildOptions& options) {
|
||||
// Extend BuildOptions to track which options were provided on command line
|
||||
struct {
|
||||
bool output_dir = false;
|
||||
bool contents_dir = false;
|
||||
bool hooks_dir = false;
|
||||
bool package_name = false;
|
||||
bool force = false;
|
||||
bool verbose = false;
|
||||
bool help = false;
|
||||
} provided;
|
||||
|
||||
// For debugging
|
||||
dpm_log(LOG_DEBUG, "Parsing command-line arguments");
|
||||
for (int i = 0; i < argc; i++) {
|
||||
@@ -22,18 +34,25 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) {
|
||||
|
||||
if (option == "--output-dir") {
|
||||
options.output_dir = value;
|
||||
provided.output_dir = true;
|
||||
} else if (option == "--contents") {
|
||||
options.contents_dir = value;
|
||||
provided.contents_dir = true;
|
||||
} else if (option == "--hooks") {
|
||||
options.hooks_dir = value;
|
||||
provided.hooks_dir = true;
|
||||
} else if (option == "--name") {
|
||||
options.package_name = value;
|
||||
provided.package_name = true;
|
||||
} else if (option == "--force") {
|
||||
options.force = true;
|
||||
provided.force = true;
|
||||
} else if (option == "--verbose") {
|
||||
options.verbose = true;
|
||||
provided.verbose = true;
|
||||
} else if (option == "--help") {
|
||||
options.show_help = true;
|
||||
provided.help = true;
|
||||
}
|
||||
|
||||
// Convert this argument to a dummy to prevent getopt from processing it
|
||||
@@ -64,24 +83,31 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) {
|
||||
switch (opt) {
|
||||
case 'o':
|
||||
options.output_dir = optarg;
|
||||
provided.output_dir = true;
|
||||
break;
|
||||
case 'c':
|
||||
options.contents_dir = optarg;
|
||||
provided.contents_dir = true;
|
||||
break;
|
||||
case 'H':
|
||||
options.hooks_dir = optarg;
|
||||
provided.hooks_dir = true;
|
||||
break;
|
||||
case 'n':
|
||||
options.package_name = optarg;
|
||||
provided.package_name = true;
|
||||
break;
|
||||
case 'f':
|
||||
options.force = true;
|
||||
provided.force = true;
|
||||
break;
|
||||
case 'v':
|
||||
options.verbose = true;
|
||||
provided.verbose = true;
|
||||
break;
|
||||
case 'h':
|
||||
options.show_help = true;
|
||||
provided.help = true;
|
||||
break;
|
||||
case '?':
|
||||
// Ignore errors as we handle equals-format options separately
|
||||
@@ -105,7 +131,40 @@ int parse_create_options(int argc, char** argv, BuildOptions& options) {
|
||||
}
|
||||
|
||||
// Log the parsed options for debugging
|
||||
dpm_log(LOG_DEBUG, ("Parsed options: contents_dir=" + options.contents_dir).c_str());
|
||||
dpm_log(LOG_DEBUG, "Parsed options:");
|
||||
|
||||
if (provided.output_dir) {
|
||||
dpm_log(LOG_DEBUG, (" output_dir=" + options.output_dir).c_str());
|
||||
}
|
||||
|
||||
if (provided.contents_dir) {
|
||||
dpm_log(LOG_DEBUG, (" contents_dir=" + options.contents_dir).c_str());
|
||||
}
|
||||
|
||||
if (provided.hooks_dir) {
|
||||
dpm_log(LOG_DEBUG, (" hooks_dir=" + options.hooks_dir).c_str());
|
||||
}
|
||||
|
||||
if (provided.package_name) {
|
||||
dpm_log(LOG_DEBUG, (" package_name=" + options.package_name).c_str());
|
||||
}
|
||||
|
||||
if (provided.force) {
|
||||
dpm_log(LOG_DEBUG, " force=true");
|
||||
}
|
||||
|
||||
if (provided.verbose) {
|
||||
dpm_log(LOG_DEBUG, " verbose=true");
|
||||
}
|
||||
|
||||
if (provided.help) {
|
||||
dpm_log(LOG_DEBUG, " help=true");
|
||||
}
|
||||
|
||||
if (!provided.output_dir && !provided.contents_dir && !provided.hooks_dir &&
|
||||
!provided.package_name && !provided.force && !provided.verbose && !provided.help) {
|
||||
dpm_log(LOG_DEBUG, " No options were provided");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user