degesch: finish the /help command

This commit is contained in:
Přemysl Eric Janouch 2015-04-25 02:08:14 +02:00
parent 05d21e8f3d
commit 29da71800a
1 changed files with 24 additions and 11 deletions

View File

@ -2893,25 +2893,38 @@ g_command_handlers[] =
"command" }, "command" },
}; };
static void
show_command_help (struct app_context *ctx,
const char *quote, struct command_handler *handler)
{
buffer_send_status (ctx, ctx->global_buffer, "%s%s: %s",
quote, handler->name, handler->description);
buffer_send_status (ctx, ctx->global_buffer, "%s Arguments: %s",
quote, handler->usage);
}
static bool static bool
handle_command_help (struct app_context *ctx, char *arguments) handle_command_help (struct app_context *ctx, char *arguments)
{ {
if (*arguments) if (!*arguments)
{ {
char *command = cut_word (&arguments); buffer_send_status (ctx, ctx->global_buffer, "%s", "");
// TODO: search for the command and show specific help buffer_send_status (ctx, ctx->global_buffer, "Commands:");
for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++)
show_command_help (ctx, " ", &g_command_handlers[i]);
return true; return true;
} }
buffer_send_status (ctx, ctx->global_buffer, "Commands:"); char *command = cut_word (&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++)
{ if (!strcasecmp_ascii (command, g_command_handlers[i].name))
struct command_handler *iter = &g_command_handlers[i]; {
buffer_send_status (ctx, ctx->global_buffer, buffer_send_status (ctx, ctx->global_buffer, "%s", "");
" %s: %s", iter->name, iter->description); show_command_help (ctx, "", &g_command_handlers[i]);
buffer_send_status (ctx, ctx->global_buffer, return true;
" Arguments: %s", iter->usage); }
} buffer_send_error (ctx, ctx->global_buffer,
"%s: %s", "No such command", command);
return true; return true;
} }