typedef struct {
char **aliases;
char *desc;
bool want_input;
bool allocated;
void *ctx;
ret_e (*body)(void *ctx, char *tok);
} opt_s;
keeps information about an option. this is the building block of your program.
char **aliases
a NULL-terminated string array keeping aliases for an option. you can
use
CLI_ALIASES(alias1, alias2, ...) to avoid manual casting
and NULL-termination.
use CLI_NONOPT, CLI_DEFAULT_OPT,
CLI_COMMON_OPT, and CLI_POST_COMMON_OPT inside
CLI_ALIASES calls to create nonopts, default opts, common
opts, and post-common opts. for these special
options,
desc is not required. a default opt triggers when the
program is ran with no args.
see ezcli/special for what these
special
options are.
char *desca probably-short string describing your option's functionality.
bool want_input
false by default. specifies if your option requires input.
ignored in nonopts and default opts.
bool allocated
this is how ezcli checks if you heap-allocated your option using
allocopt() or not. you don't need to fill this field
yourself. make sure you
see ezcli/allocopt before planning to use
allocopt().
void *ctxthis can be anything: program state, config, user data, etc. cast it inside your option body to your expected type.
ret_e body()
the actual functionality. takes context and next token (if
want_input = true). you can use
CLI_IGNORE_CTX, CLI_IGNORE_TOK, and
CLI_IGNORE_ARGS to tell the compiler arguments won’t be
used.
ret_e valuesRET_NORMAL — continue programRET_WARN — warningRET_FAIL — error (terminates unless laidback mode is
enabled)
you'd be surprised what you can do with this building block with shared context idea. you could even let the USER define the commands. weird, right?