Add list-commands and list-options to lttng ui
authorSimon Marchi <simon.marchi@ericsson.com>
Wed, 6 Jul 2011 13:25:42 +0000 (09:25 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 7 Jul 2011 14:52:30 +0000 (10:52 -0400)
Those commands are mostly for bash auto completion and does not require
heavy parsing for that matter.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
lttng/lttng.c

index e1b52c84811217714425f54ccdb2078ab4f57085..e6e657cc1ec4e59438bd011b55f5345de7894d19 100644 (file)
@@ -41,6 +41,8 @@ static char *opt_sessiond_path;
 enum {
        OPT_NO_SESSIOND,
        OPT_SESSION_PATH,
+       OPT_DUMP_OPTIONS,
+       OPT_DUMP_COMMANDS,
 };
 
 /* Getopt options. No first level command. */
@@ -51,6 +53,8 @@ static struct option long_options[] = {
        {"quiet",            0, NULL, 'q'},
        {"no-sessiond",      0, NULL, OPT_NO_SESSIOND},
        {"sessiond-path",    1, NULL, OPT_SESSION_PATH},
+       {"list-options",     0, NULL, OPT_DUMP_OPTIONS},
+       {"list-commands",    0, NULL, OPT_DUMP_COMMANDS},
        {NULL, 0, NULL, 0}
 };
 
@@ -83,6 +87,8 @@ static void usage(FILE *ofp)
        fprintf(ofp, "  -q, --quiet            Quiet mode\n");
        fprintf(ofp, "      --no-sessiond      Don't spawn a session daemon\n");
        fprintf(ofp, "      --sessiond-path    Session daemon full path\n");
+       fprintf(ofp, "      --list-options     Simple listing of lttng options\n");
+       fprintf(ofp, "      --list-commands    Simple listing of lttng commands\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Commands:\n");
        fprintf(ofp, "    add-channel     Add channel to tracer\n");
@@ -103,6 +109,49 @@ static void usage(FILE *ofp)
        fprintf(ofp, "See http://lttng.org for updates, bug reports and news.\n");
 }
 
+/*
+ *  list_options
+ *
+ *  List options line by line. This is mostly for bash auto completion and to
+ *  avoid difficult parsing.
+ */
+static void list_options(FILE *ofp)
+{
+       int i = 0;
+       struct option *option = NULL;
+
+       option = &long_options[i];
+       while (option->name != NULL) {
+               fprintf(ofp, "--%s\n", option->name);
+
+               if (isprint(option->val)) {
+                       fprintf(ofp, "-%c\n", option->val);
+               }
+
+               i++;
+               option = &long_options[i];
+       }
+}
+
+/*
+ *  list_commands
+ *
+ *  List commands line by line. This is mostly for bash auto completion and to
+ *  avoid difficult parsing.
+ */
+static void list_commands(FILE *ofp)
+{
+       int i = 0;
+       struct cmd_struct *cmd = NULL;
+
+       cmd = &commands[i];
+       while (cmd->name != NULL) {
+               fprintf(ofp, "%s\n", cmd->name);
+               i++;
+               cmd = &commands[i];
+       }
+}
+
 /*
  * clean_exit
  */
@@ -343,6 +392,14 @@ static int parse_args(int argc, char **argv)
                case OPT_SESSION_PATH:
                        opt_sessiond_path = strdup(optarg);
                        break;
+               case OPT_DUMP_OPTIONS:
+                       list_options(stdout);
+                       ret = 0;
+                       goto error;
+               case OPT_DUMP_COMMANDS:
+                       list_commands(stdout);
+                       ret = 0;
+                       goto error;
                default:
                        usage(stderr);
                        goto error;
This page took 0.025988 seconds and 4 git commands to generate.