From b2bd4b1dcb32694742b607fb6292cc73c21a82a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= Date: Thu, 9 Jun 2016 15:34:25 +0200 Subject: [PATCH 10/27] sss_tools: add commands delimiter --- src/tools/common/sss_tools.c | 18 ++++++++++++++++++ src/tools/common/sss_tools.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c index 7a3a38e5d91581a758173ddf3c6c9869641f424d..a7299c23608f25c3e943be50e780f2903dd4a736 100644 --- a/src/tools/common/sss_tools.c +++ b/src/tools/common/sss_tools.c @@ -225,6 +225,15 @@ done: return tool_ctx; } +static bool sss_tool_is_delimiter(struct sss_route_cmd *command) +{ + if (command->command != NULL && command->command[0] == '\0') { + return true; + } + + return false; +} + int sss_tool_usage(const char *tool_name, struct sss_route_cmd *commands) { @@ -234,6 +243,11 @@ int sss_tool_usage(const char *tool_name, fprintf(stderr, _("Available commands:\n")); for (i = 0; commands[i].command != NULL; i++) { + if (sss_tool_is_delimiter(&commands[i])) { + fprintf(stderr, "\n%s\n", commands[i].description); + continue; + } + if (commands[i].description == NULL) { fprintf(stderr, "* %s\n", commands[i].command); } else { @@ -268,6 +282,10 @@ int sss_tool_route(int argc, const char **argv, cmd = argv[1]; for (i = 0; commands[i].command != NULL; i++) { + if (sss_tool_is_delimiter(&commands[i])) { + continue; + } + if (strcmp(commands[i].command, cmd) == 0) { cmdline.exec = argv[0]; cmdline.command = argv[1]; diff --git a/src/tools/common/sss_tools.h b/src/tools/common/sss_tools.h index 1dd83a6fce5c8a3619f2fc7e94072d04b85ced00..2aa13d4658d3248880c01b818d8b0b9db76e1886 100644 --- a/src/tools/common/sss_tools.h +++ b/src/tools/common/sss_tools.h @@ -44,6 +44,7 @@ typedef int void *pvt); #define SSS_TOOL_COMMAND(cmd, msg, fn) {cmd, _(msg), fn} +#define SSS_TOOL_DELIMITER(message) {"", (message), NULL} struct sss_route_cmd { const char *command; -- 2.4.11