diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-09 00:10:46 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-09 00:10:46 +0200 |
commit | 1ba6db50b6004417108aeb451f07cabb9299c841 (patch) | |
tree | 735f67df9b22cca7be004aa87893434063807d95 | |
parent | f907f1e3dcf7d6922cee4433297c3b4249d899e6 (diff) | |
download | xK-1ba6db50b6004417108aeb451f07cabb9299c841.tar.gz xK-1ba6db50b6004417108aeb451f07cabb9299c841.tar.xz xK-1ba6db50b6004417108aeb451f07cabb9299c841.zip |
degesch: split handle_command_help()
-rw-r--r-- | degesch.c | 61 |
1 files changed, 34 insertions, 27 deletions
@@ -7495,42 +7495,49 @@ try_handle_command_help_option (struct app_context *ctx, const char *name) } static bool +show_command_list (struct app_context *ctx) +{ + log_global_indent (ctx, ""); + log_global_indent (ctx, "Commands:"); + + int longest = 0; + for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) + { + int len = strlen (g_command_handlers[i].name); + longest = MAX (longest, len); + } + for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) + { + struct command_handler *handler = &g_command_handlers[i]; + log_global_indent (ctx, " #&s", xstrdup_printf + ("%-*s %s", longest, handler->name, handler->description)); + } + 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) - { - log_global_indent (ctx, ""); - log_global_indent (ctx, "Commands:"); - - int longest = 0; - for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) - { - int len = strlen (g_command_handlers[i].name); - longest = MAX (longest, len); - } - for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) - { - struct command_handler *handler = &g_command_handlers[i]; - log_global_indent (ctx, " #&s", xstrdup_printf - ("%-*s %s", longest, handler->name, handler->description)); - } - return true; - } + return show_command_list (ctx); char *command = cut_word (&a->arguments); for (size_t i = 0; i < N_ELEMENTS (g_command_handlers); i++) { struct command_handler *handler = &g_command_handlers[i]; - if (strcasecmp_ascii (command, handler->name)) - continue; - - 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 (!strcasecmp_ascii (command, handler->name)) + return show_command_help (ctx, handler); } if (!try_handle_command_help_option (ctx, command)) |