degesch: split handle_command_help()

This commit is contained in:
Přemysl Eric Janouch 2015-07-09 00:10:46 +02:00
parent f907f1e3dc
commit 1ba6db50b6
1 changed files with 34 additions and 27 deletions

View File

@ -7495,11 +7495,8 @@ try_handle_command_help_option (struct app_context *ctx, const char *name)
} }
static bool static bool
handle_command_help (struct handler_args *a) show_command_list (struct app_context *ctx)
{ {
struct app_context *ctx = a->ctx;
if (!*a->arguments)
{
log_global_indent (ctx, ""); log_global_indent (ctx, "");
log_global_indent (ctx, "Commands:"); log_global_indent (ctx, "Commands:");
@ -7516,21 +7513,31 @@ handle_command_help (struct handler_args *a)
("%-*s %s", longest, handler->name, handler->description)); ("%-*s %s", longest, handler->name, handler->description));
} }
return true; return true;
} }
static bool
show_command_help (struct app_context *ctx, struct command_handler *handler)
{
log_global_indent (ctx, "");
log_global_indent (ctx, "#s: #s", handler->name, handler->description);
log_global_indent (ctx, " Arguments: #s",
handler->usage ? handler->usage : "(none)");
return true;
}
static bool
handle_command_help (struct handler_args *a)
{
struct app_context *ctx = a->ctx;
if (!*a->arguments)
return show_command_list (ctx);
char *command = cut_word (&a->arguments); char *command = cut_word (&a->arguments);
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
{ {
struct command_handler *handler = &g_command_handlers[i]; struct command_handler *handler = &g_command_handlers[i];
if (strcasecmp_ascii (command, handler->name)) if (!strcasecmp_ascii (command, handler->name))
continue; return show_command_help (ctx, handler);
log_global_indent (ctx, "");
log_global_indent (ctx, "#s: #s",
handler->name, handler->description);
log_global_indent (ctx, " Arguments: #s",
handler->usage ? handler->usage : "(none)");
return true;
} }
if (!try_handle_command_help_option (ctx, command)) if (!try_handle_command_help_option (ctx, command))