summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-25 02:08:14 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-25 02:08:14 +0200
commit29da71800a88a1fbbb9f9f10c1f335fbace95b62 (patch)
treed5503128fd3f158b899f6a7cee36e535188fe2be /degesch.c
parent05d21e8f3d8be0be92f53ba2a8ce6a0dcd35ed1b (diff)
downloadxK-29da71800a88a1fbbb9f9f10c1f335fbace95b62.tar.gz
xK-29da71800a88a1fbbb9f9f10c1f335fbace95b62.tar.xz
xK-29da71800a88a1fbbb9f9f10c1f335fbace95b62.zip
degesch: finish the /help command
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/degesch.c b/degesch.c
index baeb9d0..9bc7b8a 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2893,25 +2893,38 @@ g_command_handlers[] =
"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
handle_command_help (struct app_context *ctx, char *arguments)
{
- if (*arguments)
+ if (!*arguments)
{
- char *command = cut_word (&arguments);
- // TODO: search for the command and show specific help
+ buffer_send_status (ctx, ctx->global_buffer, "%s", "");
+ 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;
}
- 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++)
- {
- struct command_handler *iter = &g_command_handlers[i];
- buffer_send_status (ctx, ctx->global_buffer,
- " %s: %s", iter->name, iter->description);
- buffer_send_status (ctx, ctx->global_buffer,
- " Arguments: %s", iter->usage);
- }
+ if (!strcasecmp_ascii (command, g_command_handlers[i].name))
+ {
+ buffer_send_status (ctx, ctx->global_buffer, "%s", "");
+ show_command_help (ctx, "", &g_command_handlers[i]);
+ return true;
+ }
+ buffer_send_error (ctx, ctx->global_buffer,
+ "%s: %s", "No such command", command);
return true;
}