diff --git a/VERSION b/VERSION index 0aa8d57e..e49aa3c4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -a12-172-g8a3356859c+1 \ No newline at end of file +a12-173-g9886316e07+1 \ No newline at end of file diff --git a/common/include/common/option.h b/common/include/common/option.h index 3ee10e51..57af4623 100644 --- a/common/include/common/option.h +++ b/common/include/common/option.h @@ -52,7 +52,7 @@ struct Option const char * description; struct OptionValue value; - bool (*validator)(struct OptionValue * value); + bool (*validator)(struct OptionValue * value, const char ** error); void (*printHelp)(); }; @@ -68,6 +68,9 @@ bool option_get_bool (const char * module, const char * name); // called by the main application to parse the command line arguments bool option_parse(int argc, char * argv[]); +// called by the main application to validate the option values +bool option_validate(); + // print out the options, help, and their current values void option_print(); diff --git a/common/src/option.c b/common/src/option.c index 7bdb14e3..0a16ca2e 100644 --- a/common/src/option.c +++ b/common/src/option.c @@ -199,23 +199,38 @@ bool option_parse(int argc, char * argv[]) free(arg); } + return true; +} + +bool option_validate() +{ // validate the option values bool ok = true; for(int i = 0; i < state.oCount; ++i) { struct Option * o = &state.options[i]; + const char * error = NULL; if (o->validator) - if (!o->validator(&o->value)) + if (!o->validator(&o->value, &error)) { - DEBUG_ERROR("Invalid value provided to option %s:%s", o->module, o->name); + printf("\nInvalid value provided to the option: %s:%s\n", o->module, o->name); + + if (error) + printf("\n Error: %s\n", error); if (o->printHelp) + { + printf("\n"); o->printHelp(); + } ok = false; } } + if (!ok) + printf("\n"); + return ok; }