libcli/src/help.c

34 lines
636 B
C

#include <stdio.h>
#include <stddef.h>
#include "cli.h"
#include "compiler.h"
const char *
cli_arg_type_to_str(int type)
{
static const char *strs[] = {
#define X(name, str) str,
CLI_OPT_ARG_TYPES
#undef X
};
if ((size_t)type < COUNT_OF(strs))
return strs[type];
return "<ARG>";
}
void
cli_print_options(const struct option_descriptor *opts, size_t nb_opts,
t_arg_type_to_str to_str)
{
printf("Options:\n");
for (size_t i = 0; i < nb_opts; i++)
{
const char *argstr = to_str(opts[i].arg_type);
printf(" -%c, --%-15s %-8s %s\n",
opts[i].short_opt,
opts[i].long_opt,
argstr,
opts[i].description);
}
}