Clean-up: only declare help_msg in embedded help case
[lttng-tools.git] / src / bin / lttng / commands / help.c
index 5db141959d1bd089d7f8a65ea93fc957893464d3..af46296ce515e0ae070610c5184baa6e0148882f 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "../command.h"
 #include <common/utils.h>
 
-static const char *help_msg =
 #ifdef LTTNG_EMBED_HELP
+static const char *help_msg =
 #include <lttng-help.1.h>
-#else
-NULL
-#endif
 ;
+#endif
 
 static const char *lttng_help_msg =
 #ifdef LTTNG_EMBED_HELP
@@ -62,6 +61,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 +95,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 +119,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);
This page took 0.026141 seconds and 4 git commands to generate.