2 * Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include "../command.hpp"
11 #include <common/utils.hpp>
18 #ifdef LTTNG_EMBED_HELP
19 static const char *help_msg
=
20 #include <lttng-help.1.h>
24 static const char *lttng_help_msg
=
25 #ifdef LTTNG_EMBED_HELP
37 static struct poptOption long_options
[] = {
38 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
39 { "help", 'h', POPT_ARG_NONE
, nullptr, OPT_HELP
, nullptr, nullptr },
40 { "list-options", 0, POPT_ARG_NONE
, nullptr, OPT_LIST_OPTIONS
, nullptr, nullptr },
41 { nullptr, 0, 0, nullptr, 0, nullptr, nullptr }
47 int cmd_help(int argc
, const char **argv
, const struct cmd_struct commands
[])
49 int opt
, ret
= CMD_SUCCESS
;
50 const char *arg_cmd_name
;
51 static poptContext pc
;
52 const struct cmd_struct
*cmd
;
54 const char *cmd_argv
[2];
56 pc
= poptGetContext(nullptr, argc
, argv
, long_options
, 0);
57 poptReadDefaultConfig(pc
, 0);
59 while ((opt
= poptGetNextOpt(pc
)) != -1) {
64 case OPT_LIST_OPTIONS
:
65 list_cmd_options(stdout
, long_options
);
73 /* Get command name */
74 arg_cmd_name
= poptGetArg(pc
);
75 if (arg_cmd_name
== nullptr) {
76 /* Fall back to lttng(1) */
77 ret
= utils_show_help(1, "lttng", lttng_help_msg
);
79 ERR("Cannot show --help for `lttng`");
87 /* Help about help? */
88 if (strcmp(arg_cmd_name
, "help") == 0) {
93 /* Make sure command name exists */
96 while (cmd
->name
!= nullptr) {
97 if (strcmp(cmd
->name
, arg_cmd_name
) == 0) {
106 ERR("Unknown command \"%s\"", arg_cmd_name
);
111 /* Show command's help */
112 cmd_argv
[0] = cmd
->name
;
113 cmd_argv
[1] = "--help";
114 LTTNG_ASSERT(cmd
->func
);
115 ret
= cmd
->func(2, cmd_argv
);
This page took 0.031367 seconds and 4 git commands to generate.