Add descriptions to module commands

Each module command has to describe what it does. This should make module
commands self-documenting to some degree.
This commit is contained in:
Markus Mäkelä
2017-06-09 13:23:30 +03:00
parent 06995837cf
commit 45afbda100
11 changed files with 50 additions and 27 deletions

View File

@ -138,15 +138,18 @@ static MODULECMD_DOMAIN* get_or_create_domain(const char *domain)
static MODULECMD* command_create(const char *identifier, const char *domain,
enum modulecmd_type type, MODULECMDFN entry_point,
int argc, modulecmd_arg_type_t* argv)
int argc, modulecmd_arg_type_t* argv,
const char *description)
{
ss_dassert((argc && argv) || (argc == 0 && argv == NULL));
ss_dassert(description);
MODULECMD *rval = (MODULECMD*)MXS_MALLOC(sizeof(*rval));
char *id = MXS_STRDUP(identifier);
char *dm = MXS_STRDUP(domain);
char *desc = MXS_STRDUP(description);
modulecmd_arg_type_t *types = (modulecmd_arg_type_t*)MXS_MALLOC(sizeof(*types) * (argc ? argc : 1));
if (rval && id && dm && types)
if (rval && id && dm && types && desc)
{
int argc_min = 0;
@ -170,6 +173,7 @@ static MODULECMD* command_create(const char *identifier, const char *domain,
rval->func = entry_point;
rval->identifier = id;
rval->domain = dm;
rval->description = desc;
rval->arg_types = types;
rval->arg_count_min = argc_min;
rval->arg_count_max = argc;
@ -181,6 +185,7 @@ static MODULECMD* command_create(const char *identifier, const char *domain,
MXS_FREE(id);
MXS_FREE(dm);
MXS_FREE(types);
MXS_FREE(desc);
rval = NULL;
}
@ -415,7 +420,8 @@ static void free_argument(struct arg_node *arg)
bool modulecmd_register_command(const char *domain, const char *identifier,
enum modulecmd_type type, MODULECMDFN entry_point,
int argc, modulecmd_arg_type_t *argv)
int argc, modulecmd_arg_type_t *argv,
const char *description)
{
reset_error();
bool rval = false;
@ -432,7 +438,8 @@ bool modulecmd_register_command(const char *domain, const char *identifier,
}
else
{
MODULECMD *cmd = command_create(identifier, domain, type, entry_point, argc, argv);
MODULECMD *cmd = command_create(identifier, domain, type, entry_point,
argc, argv, description);
if (cmd)
{