From 6828df297bdebf234beb347aabcbb1aa596d1212 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 30 Nov 2016 15:40:43 -0500 Subject: [PATCH] lttng help: use command's --help directly MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Do the same thing for both `lttng cmd --help` and `lttng help cmd`, so that if we change what's done, the behaviour remains the same for both methods. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/help.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bin/lttng/commands/help.c b/src/bin/lttng/commands/help.c index 5db141959..6e80571e3 100644 --- a/src/bin/lttng/commands/help.c +++ b/src/bin/lttng/commands/help.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "../command.h" #include @@ -62,6 +63,7 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[]) static poptContext pc; const struct cmd_struct *cmd; int found = 0; + const char *cmd_argv[2]; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -95,6 +97,12 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[]) goto end; } + /* Help about help? */ + if (strcmp(cmd_name, "help") == 0) { + SHOW_HELP(); + goto end; + } + /* Make sure command name exists */ cmd = &commands[0]; @@ -113,14 +121,11 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[]) goto end; } - /* Show command's man page */ - ret = show_cmd_man_page(cmd_name); - - if (ret) { - ERR("Cannot view man page lttng-%s(1)", cmd_name); - perror("exec"); - ret = CMD_ERROR; - } + /* Show command's help */ + cmd_argv[0] = cmd->name; + cmd_argv[1] = "--help"; + assert(cmd->func); + ret = cmd->func(2, cmd_argv); end: poptFreeContext(pc); -- 2.34.1