Add a '--list-options' option to each command.
authorSimon Marchi <simon.marchi@polymtl.ca>
Tue, 24 Jan 2012 16:28:04 +0000 (11:28 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 24 Jan 2012 17:10:37 +0000 (12:10 -0500)
This is intended to be used for programmable Bash completion.

Modified from previous version:
- Changed '\0' to 0 to match current coding style.

Changes made by David Goulet:
- Check args for --list-options in lttng cli to stop auto execution of
  the session daemon.
- Adds --list-options to all help. (Hidding command is bad :P)
- Fix uninitialized ret value in enable channel

Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
16 files changed:
src/bin/lttng/commands/add_context.c
src/bin/lttng/commands/calibrate.c
src/bin/lttng/commands/create.c
src/bin/lttng/commands/destroy.c
src/bin/lttng/commands/disable_channels.c
src/bin/lttng/commands/disable_events.c
src/bin/lttng/commands/enable_channels.c
src/bin/lttng/commands/enable_events.c
src/bin/lttng/commands/list.c
src/bin/lttng/commands/set_session.c
src/bin/lttng/commands/start.c
src/bin/lttng/commands/stop.c
src/bin/lttng/commands/version.c
src/bin/lttng/lttng.c
src/bin/lttng/utils.c
src/bin/lttng/utils.h

index 260c300be8a5483f562902ea666ca3d22a82a34c..82abc73332ad10b1117a7e95a954f39f4256108e 100644 (file)
@@ -48,6 +48,7 @@ enum {
        OPT_HELP = 1,
        OPT_TYPE,
        OPT_USERSPACE,
+       OPT_LIST_OPTIONS,
 };
 
 static struct lttng_handle *handle;
@@ -149,6 +150,7 @@ static struct poptOption long_options[] = {
        {"userspace",      'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
 #endif
        {"type",           't', POPT_ARG_STRING, &opt_type, OPT_TYPE, 0, 0},
+       {"list-options",   0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -307,6 +309,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "\n");
        fprintf(ofp, "Options:\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -s, --session            Apply on session name\n");
        fprintf(ofp, "  -c, --channel NAME       Apply on channel\n");
        fprintf(ofp, "  -e, --event NAME         Apply on event\n");
@@ -463,6 +466,10 @@ int cmd_add_context(int argc, const char **argv)
                        opt_cmd_name = poptGetOptArg(pc);
 #endif
                        break;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index a0e852f8b03984836717c4d5c5317c08d7cbb696..81eadbfd2b6d54499fd7d657e49a051361ac0c8b 100644 (file)
@@ -48,6 +48,7 @@ enum {
        OPT_FUNCTION_ENTRY,
        OPT_SYSCALL,
        OPT_USERSPACE,
+       OPT_LIST_OPTIONS,
 };
 
 static struct lttng_handle *handle;
@@ -75,6 +76,7 @@ static struct poptOption long_options[] = {
        {"function:entry", 0,   POPT_ARG_NONE, 0, OPT_FUNCTION_ENTRY, 0, 0},
 #endif
        {"syscall",        0,   POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -86,6 +88,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng calibrate [options] [calibrate_options]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
 #if 0
        fprintf(ofp, "  -u, --userspace [CMD]    Apply for the user-space tracer\n");
@@ -217,6 +220,10 @@ int cmd_calibrate(int argc, const char **argv)
                case OPT_USERSPACE:
                        opt_userspace = 1;
                        break;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index 835d82a4f9d7c7b9523a574fb0ef6cda53f8de5f..a791fbd4df43710c0ae024ee09a4a477d6de5eae 100644 (file)
 #include <unistd.h>
 
 #include "../command.h"
+#include "../utils.h"
 
 static char *opt_output_path;
 static char *opt_session_name;
 
 enum {
        OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
-       {"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
-       {"output",    'o', POPT_ARG_STRING, &opt_output_path, 0, 0, 0},
+       {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL},
+       {"output", 'o', POPT_ARG_STRING, &opt_output_path, 0, NULL, NULL},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -50,6 +53,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng create [options] [NAME]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help           Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -o, --output PATH    Specify output path for traces\n");
        fprintf(ofp, "\n");
 }
@@ -160,6 +164,10 @@ int cmd_create(int argc, const char **argv)
                case OPT_HELP:
                        usage(stderr);
                        goto end;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index b7931595879b607dca82186f36905f7f6335abd2..39b4e9a2f6dbe00d0b6a63d6c372455dc07fbfb8 100644 (file)
@@ -31,11 +31,13 @@ static char *opt_session_name;
 
 enum {
        OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -50,6 +52,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "get it from the configuration directory (.lttng).\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help           Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "\n");
 }
 
@@ -116,6 +119,10 @@ int cmd_destroy(int argc, const char **argv)
                case OPT_HELP:
                        usage(stderr);
                        goto end;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index f8ed51759a35a1481e5e6e233e3c9ec7dfd13343..55564bc3d604eebc96968f25fac779152238e7bf 100644 (file)
@@ -40,6 +40,7 @@ static pid_t opt_pid;
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
+       OPT_LIST_OPTIONS,
 };
 
 static struct lttng_handle *handle;
@@ -56,6 +57,7 @@ static struct poptOption long_options[] = {
 #else
        {"userspace",      'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
 #endif
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -67,6 +69,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -s, --session            Apply on session name\n");
        fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
 #if 0
@@ -153,6 +156,10 @@ int cmd_disable_channels(int argc, const char **argv)
                case OPT_USERSPACE:
                        opt_userspace = 1;
                        break;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index 7446168d2a3d850bbf1f4a501ea605c4cffb9f01..ff42da0e001c552c6b6f49c3d9a58b3126ecc4c1 100644 (file)
@@ -42,6 +42,7 @@ static pid_t opt_pid;
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
+       OPT_LIST_OPTIONS,
 };
 
 static struct lttng_handle *handle;
@@ -60,6 +61,7 @@ static struct poptOption long_options[] = {
 #else
        {"userspace",      'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
 #endif
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -71,6 +73,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -s, --session            Apply on session name\n");
        fprintf(ofp, "  -c, --channel            Apply on this channel\n");
        fprintf(ofp, "  -a, --all-events         Disable all tracepoints\n");
@@ -211,6 +214,10 @@ int cmd_disable_events(int argc, const char **argv)
                case OPT_USERSPACE:
                        opt_userspace = 1;
                        break;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index 5443d78a3c8826138cf9e3813de8ea88936befa8..e27fe88cecff1a826e62e849539bdaa4187a8a93 100644 (file)
@@ -48,6 +48,7 @@ enum {
        OPT_SWITCH_TIMER,
        OPT_READ_TIMER,
        OPT_USERSPACE,
+       OPT_LIST_OPTIONS,
 };
 
 static struct lttng_handle *handle;
@@ -70,6 +71,7 @@ static struct poptOption long_options[] = {
        {"num-subbuf",     0,   POPT_ARG_INT, 0, OPT_NUM_SUBBUF, 0, 0},
        {"switch-timer",   0,   POPT_ARG_INT, 0, OPT_SWITCH_TIMER, 0, 0},
        {"read-timer",     0,   POPT_ARG_INT, 0, OPT_READ_TIMER, 0, 0},
+       {"list-options",   0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -81,6 +83,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng enable-channel NAME[,NAME2,...] [options] [channel_options]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -s, --session            Apply on session name\n");
        fprintf(ofp, "  -k, --kernel             Apply on the kernel tracer\n");
 #if 0
@@ -258,6 +261,10 @@ int cmd_enable_channels(int argc, const char **argv)
                case OPT_USERSPACE:
                        opt_userspace = 1;
                        break;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index c5a969f208e5fa66d11494a7aa49d41f4052fa5e..41a25730cdc4f5495d534fce5d21214ee46d9305 100644 (file)
@@ -54,6 +54,7 @@ enum {
        OPT_SYSCALL,
        OPT_USERSPACE,
        OPT_TRACEPOINT_LOGLEVEL,
+       OPT_LIST_OPTIONS,
 };
 
 static struct lttng_handle *handle;
@@ -84,6 +85,7 @@ static struct poptOption long_options[] = {
 #endif
        {"syscall",        0,   POPT_ARG_NONE, 0, OPT_SYSCALL, 0, 0},
        {"loglevel",     0,     POPT_ARG_NONE, 0, OPT_TRACEPOINT_LOGLEVEL, 0, 0},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -95,6 +97,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [options] [event_options]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -s, --session            Apply on session name\n");
        fprintf(ofp, "  -c, --channel            Apply on this channel\n");
        fprintf(ofp, "  -a, --all                Enable all tracepoints\n");
@@ -432,6 +435,10 @@ int cmd_enable_events(int argc, const char **argv)
                case OPT_TRACEPOINT_LOGLEVEL:
                        opt_event_type = LTTNG_EVENT_TRACEPOINT_LOGLEVEL;
                        break;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index f09edaef474ce76660fd67aad1867d42bc7b4550..743b79ff2431f826ec2d623fe1957c834bff0a0d 100644 (file)
@@ -43,6 +43,7 @@ const char *indent8 = "        ";
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
+       OPT_LIST_OPTIONS,
 };
 
 static struct lttng_handle *handle;
@@ -60,6 +61,7 @@ static struct poptOption long_options[] = {
 #endif
        {"channel",   'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
        {"domain",    'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -76,6 +78,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "With -u alone, list available userspace events\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help              Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "  -k, --kernel            Select kernel domain\n");
        fprintf(ofp, "  -u, --userspace         Select user-space domain.\n");
 #if 0
@@ -556,6 +559,10 @@ int cmd_list(int argc, const char **argv)
                case OPT_USERSPACE:
                        opt_userspace = 1;
                        break;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index bc25b8d1e3ad5124192e6a436e76f9b5d9a4cd24..f91935e045072d5d71bf551c0fbb8108b90ee6fe 100644 (file)
@@ -31,11 +31,13 @@ static char *opt_session_name;
 
 enum {
        OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",           'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"list-options",   0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -48,6 +50,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "\n");
        fprintf(ofp, "Options:\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "\n");
 }
 
@@ -89,6 +92,10 @@ int cmd_set_session(int argc, const char **argv)
                        usage(stderr);
                        ret = CMD_SUCCESS;
                        goto end;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index 8292787731e4bc36360588d5df3ba4b3ab0a52d4..b2a4980055f4c480a1798b5c599e872a81c1ac93 100644 (file)
@@ -31,11 +31,13 @@ static char *opt_session_name;
 
 enum {
        OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -50,6 +52,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "get it from the configuration directory (.lttng).\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "\n");
 }
 
@@ -109,6 +112,10 @@ int cmd_start(int argc, const char **argv)
                        usage(stderr);
                        ret = CMD_SUCCESS;
                        goto end;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index 0a942645db70b5b278e8af8c8b3f5e780d706ce2..82c9b4e13fb03baea2a3eff5146902ffbe60ddd3 100644 (file)
@@ -31,11 +31,13 @@ static char *opt_session_name;
 
 enum {
        OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -50,6 +52,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "get it from the configuration directory (.lttng).\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "\n");
 }
 
@@ -106,6 +109,10 @@ int cmd_stop(int argc, const char **argv)
                        usage(stderr);
                        ret = CMD_SUCCESS;
                        goto end;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index c9b547bce2a2a844e6cd22e58e0a962a9ae8f7b0..f288ba4aa971e30e1e9c615f1f4dd629664b07ce 100644 (file)
 
 enum {
        OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
 };
 
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        {"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+       {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -46,6 +48,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "usage: lttng version\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "      --list-options       Simple listing of options\n");
        fprintf(ofp, "\n");
 }
 
@@ -66,6 +69,10 @@ int cmd_version(int argc, const char **argv)
                        usage(stderr);
                        ret = CMD_SUCCESS;
                        goto end;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       ret = CMD_SUCCESS;
+                       goto end;
                default:
                        usage(stderr);
                        ret = CMD_UNDEFINED;
index 031b015efba4dd05da900b25a8d0c8ead4dfa7b7..64f3efa446530ed61663c9434eb77251cc923c91 100644 (file)
@@ -377,15 +377,19 @@ end:
 }
 
 /*
- * Check for the "help" option in the argv. If found, return 1 else return 0.
+ * Check args for specific options that *must* not trigger a session daemon
+ * execution.
+ *
+ * Return 1 if match else 0.
  */
-static int check_help_command(int argc, char **argv)
+static int check_args_no_sessiond(int argc, char **argv)
 {
        int i;
 
        for (i = 0; i < argc; i++) {
                if ((strncmp(argv[i], "-h", 2) == 0) ||
-                               strncmp(argv[i], "--h", 3) == 0) {
+                               strncmp(argv[i], "--h", 3) == 0 ||
+                               strncmp(argv[i], "--list-options", 14)) {
                        return 1;
                }
        }
@@ -448,7 +452,7 @@ static int parse_args(int argc, char **argv)
        }
 
        /* Spawn session daemon if needed */
-       if (opt_no_sessiond == 0 && check_help_command(argc, argv) == 0 &&
+       if (opt_no_sessiond == 0 && check_args_no_sessiond(argc, argv) == 0 &&
                        (check_sessiond() < 0)) {
                goto error;
        }
index e993f0f7231c8c5b71ef6363e37598f5ba4bda5a..635bf7734d244a0694135c5ac3b827644d72d9a8 100644 (file)
  */
 
 #include <stdlib.h>
+#include <ctype.h>
 
 #include <common/error.h>
 
 #include "conf.h"
+#include "utils.h"
 
 /*
  *  get_session_name
@@ -48,3 +50,26 @@ error:
        DBG("Session name found: %s", session_name);
        return session_name;
 }
+
+
+/*
+ * list_cmd_options
+ *
+ * Prints a simple list of the options available to a command. This is intended
+ * to be easily parsed for bash completion.
+ */
+void list_cmd_options(FILE *ofp, struct poptOption *options)
+{
+       int i;
+       struct poptOption *option = NULL;
+
+       for (i = 0; options[i].longName != NULL; i++) {
+               option = &options[i];
+
+               fprintf(ofp, "--%s\n", option->longName);
+
+               if (isprint(option->shortName)) {
+                       fprintf(ofp, "-%c\n", option->shortName);
+               }
+       }
+}
index 5492d5e67f8abd38cff8561b57ebf3cf8e0a41af..e609b7086926df453b7ce98a8f81942f30914842 100644 (file)
 #ifndef _LTTNG_UTILS_H
 #define _LTTNG_UTILS_H
 
+#include <popt.h>
+
 char *get_config_file_path(void);
 char *get_session_name(void);
 int set_session_name(char *name);
+void list_cmd_options(FILE *ofp, struct poptOption *options);
 
 #endif /* _LTTNG_UTILS_H */
This page took 0.036343 seconds and 4 git commands to generate.