cmd: add support for dynamically generating command options at runtime

This commit is contained in:
2026-02-03 14:46:40 +00:00
parent f5c4fa561f
commit 2632feac32
3 changed files with 47 additions and 3 deletions

View File

@@ -282,6 +282,24 @@ struct b_command_usage *b_command_add_usage(struct b_command *cmd)
return usage;
}
const struct b_command_option *b_command_get_option(
const struct b_command *cmd, int id)
{
struct b_queue_entry *cur = b_queue_first(&cmd->b_opt);
while (cur) {
const struct b_command_option *opt
= b_unbox(struct b_command_option, cur, opt_entry);
if (opt->opt_id == id) {
return opt;
}
cur = b_queue_next(cur);
}
return NULL;
}
b_status b_command_usage_add_option(
struct b_command_usage *usage, struct b_command_option *opt)
{
@@ -335,9 +353,9 @@ b_status b_command_usage_add_command(b_command_usage *usage, unsigned int cmd_id
static void prepend_command_name(struct b_command *cmd, b_string *out)
{
int nr_names = 0;
cmd->b_name&& nr_names++;
cmd->b_long_name&& nr_names++;
cmd->b_short_name&& nr_names++;
cmd->b_name &&nr_names++;
cmd->b_long_name &&nr_names++;
cmd->b_short_name &&nr_names++;
if (nr_names > 1) {
b_string_prepend_cstr(out, "}");