From: Simon Marchi Date: Tue, 13 Aug 2013 20:26:23 +0000 (-0400) Subject: Add --list-commands option to the snapshot command X-Git-Tag: v2.3.0-rc3~26 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3c9bd23cc5999729bb49a973d8c1e2bedef939bb;p=lttng-tools.git Add --list-commands option to the snapshot command It lists snapshot sub-commands. This involves moving list_commands to utils so that commands can use it. Signed-off-by: Simon Marchi Signed-off-by: David Goulet --- diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c index dd1137baa..a357730d0 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -50,6 +50,7 @@ enum { OPT_HELP = 1, OPT_LIST_OPTIONS, OPT_MAX_SIZE, + OPT_LIST_COMMANDS, }; static struct poptOption snapshot_opts[] = { @@ -61,6 +62,7 @@ static struct poptOption snapshot_opts[] = { {"name", 'n', POPT_ARG_STRING, &opt_output_name, 0, 0, 0}, {"max-size", 'm', POPT_ARG_STRING, 0, OPT_MAX_SIZE, 0, 0}, {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, + {"list-commands", 0, POPT_ARG_NONE, NULL, OPT_LIST_COMMANDS}, {0, 0, 0, 0, 0, 0, 0} }; @@ -440,6 +442,9 @@ int cmd_snapshot(int argc, const char **argv) case OPT_LIST_OPTIONS: list_cmd_options(stdout, snapshot_opts); goto end; + case OPT_LIST_COMMANDS: + list_commands(actions, stdout); + goto end; case OPT_MAX_SIZE: { uint64_t val; diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 5755db637..dc9dd9241 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -150,25 +150,6 @@ static void list_options(FILE *ofp) } } -/* - * 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 */ @@ -466,7 +447,7 @@ static int parse_args(int argc, char **argv) ret = 0; goto end; case OPT_DUMP_COMMANDS: - list_commands(stdout); + list_commands(commands, stdout); ret = 0; goto end; default: diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index 6041655dd..e40c3fd70 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -25,6 +25,7 @@ #include "conf.h" #include "utils.h" +#include "command.h" /* * get_session_name @@ -56,6 +57,24 @@ error: return NULL; } +/* + * list_commands + * + * List commands line by line. This is mostly for bash auto completion and to + * avoid difficult parsing. + */ +void list_commands(struct cmd_struct *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]; + } +} /* * list_cmd_options diff --git a/src/bin/lttng/utils.h b/src/bin/lttng/utils.h index 57bec1250..fb973caa5 100644 --- a/src/bin/lttng/utils.h +++ b/src/bin/lttng/utils.h @@ -20,7 +20,10 @@ #include +struct cmd_struct; + char *get_session_name(void); +void list_commands(struct cmd_struct *commands, FILE *ofp); void list_cmd_options(FILE *ofp, struct poptOption *options); /*