cmd: add functions to report option/arg errors to the public API
This commit is contained in:
@@ -19,6 +19,18 @@
|
||||
= b_arglist_iterator_begin(q, opt_id, arg_id, (it)); \
|
||||
b_arglist_iterator_is_valid(it); b_arglist_iterator_next(it))
|
||||
|
||||
#define b_arglist_option_foreach(it, q) \
|
||||
for (int z__b_unique_name() \
|
||||
= b_arglist_option_iterator_begin(q, B_COMMAND_INVALID_ID, (it)); \
|
||||
b_arglist_option_iterator_is_valid(it); \
|
||||
b_arglist_option_iterator_next(it))
|
||||
|
||||
#define b_arglist_option_foreach_filtered(it, q, opt_id) \
|
||||
for (int z__b_unique_name() \
|
||||
= b_arglist_option_iterator_begin(q, opt_id, (it)); \
|
||||
b_arglist_option_iterator_is_valid(it); \
|
||||
b_arglist_option_iterator_next(it))
|
||||
|
||||
#define B_COMMAND(id, parent_id) \
|
||||
static b_command *command_##id = NULL; \
|
||||
static void __init_##id( \
|
||||
@@ -105,15 +117,13 @@
|
||||
b_command_usage_add_option(this_usage, opt_##opt_id)
|
||||
|
||||
#define B_COMMAND_USAGE_OPT_PLACEHOLDER() \
|
||||
b_command_usage_add_option( \
|
||||
this_usage, (struct b_command_option *)B_COMMAND_INVALID_ID)
|
||||
b_command_usage_add_option(this_usage, NULL)
|
||||
|
||||
#define B_COMMAND_USAGE_ARG(opt_id) \
|
||||
b_command_usage_add_arg(this_usage, arg_##opt_id)
|
||||
|
||||
#define B_COMMAND_USAGE_ARG_PLACEHOLDER() \
|
||||
b_command_usage_add_arg( \
|
||||
this_usage, (struct b_command_arg *)B_COMMAND_INVALID_ID)
|
||||
b_command_usage_add_arg(this_usage, NULL)
|
||||
|
||||
#define B_COMMAND_OPTION_HELP ((uintptr_t)0xF0000001)
|
||||
#define B_COMMAND_INVALID_ID ((uintptr_t)0xFFFFFFFF)
|
||||
@@ -164,6 +174,17 @@ typedef struct b_arglist_iterator {
|
||||
unsigned int _opt_filter, _arg_filter;
|
||||
} b_arglist_iterator;
|
||||
|
||||
typedef struct b_arglist_option_iterator {
|
||||
b_iterator _base;
|
||||
size_t i;
|
||||
|
||||
unsigned int opt_id;
|
||||
struct b_arglist_option *opt;
|
||||
|
||||
b_btree_iterator _opt_it;
|
||||
unsigned int _opt_filter;
|
||||
} b_arglist_option_iterator;
|
||||
|
||||
typedef struct b_command b_command;
|
||||
typedef struct b_command_option b_command_option;
|
||||
typedef struct b_command_arg b_command_arg;
|
||||
@@ -228,6 +249,17 @@ BLUE_API b_status b_arglist_get_option(
|
||||
BLUE_API size_t b_arglist_get_count(
|
||||
const b_arglist *args, unsigned int opt_id, unsigned int arg_id);
|
||||
|
||||
BLUE_API b_status b_arglist_report_missing_option(
|
||||
const b_arglist *args, unsigned int opt_id);
|
||||
BLUE_API b_status b_arglist_report_unexpected_arg(
|
||||
const b_arglist *args, const char *value);
|
||||
BLUE_API b_status b_arglist_report_invalid_arg_value(
|
||||
const b_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
const char *value);
|
||||
BLUE_API b_status b_arglist_report_missing_args(
|
||||
const b_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
size_t nr_supplied);
|
||||
|
||||
BLUE_API b_status b_arglist_option_get_value(
|
||||
const b_arglist_option *opt, unsigned int arg_id, unsigned int index,
|
||||
b_arglist_value **out);
|
||||
@@ -238,4 +270,11 @@ BLUE_API int b_arglist_iterator_begin(
|
||||
BLUE_API bool b_arglist_iterator_next(b_arglist_iterator *it);
|
||||
BLUE_API bool b_arglist_iterator_is_valid(const b_arglist_iterator *it);
|
||||
|
||||
BLUE_API int b_arglist_option_iterator_begin(
|
||||
const b_arglist *args, unsigned int opt_filter,
|
||||
b_arglist_option_iterator *it);
|
||||
BLUE_API bool b_arglist_option_iterator_next(b_arglist_option_iterator *it);
|
||||
BLUE_API bool b_arglist_option_iterator_is_valid(
|
||||
const b_arglist_option_iterator *it);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user