[ltt-dev] [PATCH] This allows to list the command-specific options in order to make more accurate bash completion.

Mathieu Desnoyers compudj at krystal.dyndns.org
Thu Aug 4 17:09:38 EDT 2011


* simon.marchi at polymtl.ca (simon.marchi at polymtl.ca) wrote:
> From: Simon Marchi <simon.marchi at ericsson.com>
> 
> Second attempt, fix formatting:
> - Replace spaces by tab in cmd_*
> - Same in list_cmd_options
> - Replaced while by for construct in list_cmd_options
> 

I'll let David Goulet deal with the merge.

Acked-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>

Thanks!

Mathieu

> Signed-off-by: Simon Marchi <simon.marchi at polymtl.ca>
> ---
>  lttng/commands/add_context.c      |    9 +++++++++
>  lttng/commands/create.c           |   11 +++++++++--
>  lttng/commands/destroy.c          |    9 ++++++++-
>  lttng/commands/disable_channels.c |    8 ++++++++
>  lttng/commands/disable_events.c   |    8 ++++++++
>  lttng/commands/enable_channels.c  |    8 ++++++++
>  lttng/commands/enable_events.c    |   10 +++++++++-
>  lttng/commands/list.c             |   20 ++++++++++++++------
>  lttng/commands/set_session.c      |    8 ++++++++
>  lttng/commands/start.c            |    9 ++++++++-
>  lttng/commands/stop.c             |    9 ++++++++-
>  lttng/commands/version.c          |   10 +++++++++-
>  lttng/utils.c                     |   25 +++++++++++++++++++++++++
>  lttng/utils.h                     |    3 +++
>  14 files changed, 134 insertions(+), 13 deletions(-)
> 
> diff --git a/lttng/commands/add_context.c b/lttng/commands/add_context.c
> index 5756684..9b7f3c6 100644
> --- a/lttng/commands/add_context.c
> +++ b/lttng/commands/add_context.c
> @@ -45,6 +45,7 @@ static pid_t opt_pid;
>  enum {
>  	OPT_HELP = 1,
>  	OPT_TYPE,
> +	OPT_LISTOPTS,
>  };
>  
>  /*
> @@ -140,6 +141,7 @@ static struct poptOption long_options[] = {
>  	{"all",            0,   POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
>  	{"pid",            'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
>  	{"type",           't', POPT_ARG_STRING, 0, OPT_TYPE, 0, 0},
> +	{"list-options",   0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -311,6 +313,9 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "                           TYPE can be one of the strings below:\n");
>  	print_ctx_type(ofp);
>  	fprintf(ofp, "\n");
> +	fprintf(ofp, "  --list-options           Prints a simple list of options specific to\n");
> +	fprintf(ofp, "                           add-context\n");
> +	fprintf(ofp, "\n");
>  	fprintf(ofp, "Example:\n");
>  	fprintf(ofp, "This command will add the context information 'prio' and two perf\n"
>  			"counters: hardware branch misses and cache misses, to all events\n"
> @@ -454,6 +459,10 @@ int cmd_add_context(int argc, const char **argv)
>  			}
>  			free(tmp);
>  			break;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/create.c b/lttng/commands/create.c
> index 4083e41..bc54264 100644
> --- a/lttng/commands/create.c
> +++ b/lttng/commands/create.c
> @@ -35,12 +35,14 @@ static char *opt_session_name;
>  
>  enum {
>  	OPT_HELP = 1,
> +	OPT_LISTOPTS,
>  };
>  
>  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, 0, OPT_HELP, 0, 0},
> +	{"output",       'o', POPT_ARG_STRING, &opt_output_path, 0, 0, 0},
> +	{"list-options", 0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -53,6 +55,7 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "\n");
>  	fprintf(ofp, "  -h, --help           Show this help\n");
>  	fprintf(ofp, "  -o, --output PATH    Specify output path for traces\n");
> +	fprintf(ofp, "  --list-options       Prints a simple list of options specific to create\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -162,6 +165,10 @@ int cmd_create(int argc, const char **argv)
>  		case OPT_HELP:
>  			usage(stderr);
>  			goto end;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/destroy.c b/lttng/commands/destroy.c
> index 516f8ab..fb652b5 100644
> --- a/lttng/commands/destroy.c
> +++ b/lttng/commands/destroy.c
> @@ -33,11 +33,13 @@ static char *opt_session_name;
>  
>  enum {
>  	OPT_HELP = 1,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
>  	/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
> -	{"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"help",         'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"list-options", 0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -52,6 +54,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       Prints a simple list of options specific to destroy\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -122,6 +125,10 @@ int cmd_destroy(int argc, const char **argv)
>  		case OPT_HELP:
>  			usage(stderr);
>  			goto end;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/disable_channels.c b/lttng/commands/disable_channels.c
> index c23019b..fa2ba18 100644
> --- a/lttng/commands/disable_channels.c
> +++ b/lttng/commands/disable_channels.c
> @@ -39,6 +39,7 @@ static pid_t opt_pid;
>  enum {
>  	OPT_HELP = 1,
>  	OPT_USERSPACE,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
> @@ -49,6 +50,7 @@ static struct poptOption long_options[] = {
>  	{"userspace",      'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
>  	{"all",            0,   POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
>  	{"pid",            'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
> +	{"list-options",   0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -65,6 +67,8 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "  -u, --userspace       Apply for the user-space tracer\n");
>  	fprintf(ofp, "      --all             If -u, apply on all traceable apps\n");
>  	fprintf(ofp, "  -p, --pid PID         If -u, apply on a specific PID\n");
> +	fprintf(ofp, "  --list-options        Prints a simple list of options specific to\n");
> +	fprintf(ofp, "                        disable-channel\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -144,6 +148,10 @@ int cmd_disable_channels(int argc, const char **argv)
>  		case OPT_USERSPACE:
>  			opt_userspace = 1;
>  			break;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/disable_events.c b/lttng/commands/disable_events.c
> index 952b2b6..e7d9e5b 100644
> --- a/lttng/commands/disable_events.c
> +++ b/lttng/commands/disable_events.c
> @@ -42,6 +42,7 @@ static pid_t opt_pid;
>  enum {
>  	OPT_HELP = 1,
>  	OPT_USERSPACE,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
> @@ -54,6 +55,7 @@ static struct poptOption long_options[] = {
>  	{"userspace",      'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0},
>  	{"all",            0,   POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
>  	{"pid",            'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
> +	{"list-options",   0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -72,6 +74,8 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "  -u, --userspace [CMD]    Apply for the user-space tracer\n");
>  	fprintf(ofp, "      --all                If -u, apply on all traceable apps\n");
>  	fprintf(ofp, "  -p, --pid PID            If -u, apply on a specific PID\n");
> +	fprintf(ofp, "  --list-options           Prints a simple list of options specific to\n");
> +	fprintf(ofp, "                           disable-event\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -181,6 +185,10 @@ int cmd_disable_events(int argc, const char **argv)
>  			opt_userspace = 1;
>  			opt_cmd_name = poptGetOptArg(pc);
>  			break;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/enable_channels.c b/lttng/commands/enable_channels.c
> index efd075b..0208a3b 100644
> --- a/lttng/commands/enable_channels.c
> +++ b/lttng/commands/enable_channels.c
> @@ -48,6 +48,7 @@ enum {
>  	OPT_SWITCH_TIMER,
>  	OPT_READ_TIMER,
>  	OPT_USERSPACE,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
> @@ -64,6 +65,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, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -80,6 +82,8 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "  -u, --userspace [CMD]    Apply on the user-space tracer\n");
>  	fprintf(ofp, "      --all                If -u, apply on all traceable apps\n");
>  	fprintf(ofp, "  -p, --pid PID            If -u, apply on a specific PID\n");
> +	fprintf(ofp, "  --list-options           Prints a simple list of options specific to\n");
> +	fprintf(ofp, "                           enable-channel\n");
>  	fprintf(ofp, "\n");
>  	fprintf(ofp, "Channel options:\n");
>  	fprintf(ofp, "      --discard            Discard event when buffers are full (default)\n");
> @@ -212,6 +216,10 @@ int cmd_enable_channels(int argc, const char **argv)
>  			chan.attr.read_timer_interval = atoi(poptGetOptArg(pc));
>  			DBG("Channel read timer interval set to %d", chan.attr.read_timer_interval);
>  			break;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/enable_events.c b/lttng/commands/enable_events.c
> index b99b7f4..64d1aeb 100644
> --- a/lttng/commands/enable_events.c
> +++ b/lttng/commands/enable_events.c
> @@ -53,6 +53,7 @@ enum {
>  	OPT_PROBE,
>  	OPT_FUNCTION,
>  	OPT_FUNCTION_ENTRY,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
> @@ -67,9 +68,10 @@ static struct poptOption long_options[] = {
>  	{"pid",            'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
>  	{"tracepoint",     0,   POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
>  	{"marker",         0,   POPT_ARG_NONE, 0, OPT_MARKER, 0, 0},
> -	{"probe",         0,   POPT_ARG_STRING, 0, OPT_PROBE, 0, 0},
> +	{"probe",          0,   POPT_ARG_STRING, 0, OPT_PROBE, 0, 0},
>  	{"function",       0,   POPT_ARG_STRING, 0, OPT_FUNCTION, 0, 0},
>  	{"function:entry", 0,   POPT_ARG_STRING, 0, OPT_FUNCTION_ENTRY, 0, 0},
> +	{"list-options",   0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -88,6 +90,8 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "  -u, --userspace [CMD]    Apply for the user-space tracer\n");
>  	fprintf(ofp, "      --all                If -u, apply on all traceable apps\n");
>  	fprintf(ofp, "  -p, --pid PID            If -u, apply on a specific PID\n");
> +	fprintf(ofp, "  --list-options           Prints a simple list of options specific to\n");
> +	fprintf(ofp, "                           enable-event\n");
>  	fprintf(ofp, "\n");
>  	fprintf(ofp, "Event options:\n");
>  	fprintf(ofp, "    --tracepoint           Tracepoint event (default)\n");
> @@ -334,6 +338,10 @@ int cmd_enable_events(int argc, const char **argv)
>  			opt_event_type = LTTNG_EVENT_FUNCTION_ENTRY;
>  			opt_function_entry_symbol = poptGetOptArg(pc);
>  			break;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/list.c b/lttng/commands/list.c
> index 3c779c3..b827894 100644
> --- a/lttng/commands/list.c
> +++ b/lttng/commands/list.c
> @@ -24,6 +24,7 @@
>  #include <string.h>
>  
>  #include "../cmd.h"
> +#include "../utils.h"
>  
>  static int opt_pid;
>  static int opt_userspace;
> @@ -37,16 +38,18 @@ const char *indent8 = "        ";
>  
>  enum {
>  	OPT_HELP = 1,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
>  	/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
> -	{"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> -	{"kernel",    'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
> -	{"userspace", 'u', POPT_ARG_VAL, &opt_userspace, 1, 0, 0},
> -	{"pid",       'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
> -	{"channel",   'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
> -	{"domain",    'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
> +	{"help",         'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"kernel",       'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
> +	{"userspace",    'u', POPT_ARG_VAL, &opt_userspace, 1, 0, 0},
> +	{"pid",          'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
> +	{"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, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -66,6 +69,7 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "  -k, --kernel            Select kernel domain\n");
>  	fprintf(ofp, "  -u, --userspace         Select user-space domain.\n");
>  	fprintf(ofp, "  -p, --pid PID           List user-space events by PID\n");
> +	fprintf(ofp, "  --list-options          Prints a simple list of options specific to list\n");
>  	fprintf(ofp, "\n");
>  	fprintf(ofp, "Options:\n");
>  	fprintf(ofp, "  -c, --channel NAME      List details of a channel\n");
> @@ -391,6 +395,10 @@ int cmd_list(int argc, const char **argv)
>  		case OPT_HELP:
>  			usage(stderr);
>  			goto end;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/set_session.c b/lttng/commands/set_session.c
> index 8a76403..76cafa1 100644
> --- a/lttng/commands/set_session.c
> +++ b/lttng/commands/set_session.c
> @@ -33,11 +33,13 @@ static char *opt_session_name;
>  
>  enum {
>  	OPT_HELP = 1,
> +	OPT_LISTOPTS,
>  };
>  
>  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, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -50,6 +52,8 @@ static void usage(FILE *ofp)
>  	fprintf(ofp, "\n");
>  	fprintf(ofp, "Options:\n");
>  	fprintf(ofp, "  -h, --help               Show this help\n");
> +	fprintf(ofp, "  --list-options           Prints a simple list of options specific to\n");
> +	fprintf(ofp, "                           set-session\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -91,6 +95,10 @@ int cmd_set_session(int argc, const char **argv)
>  			usage(stderr);
>  			ret = CMD_SUCCESS;
>  			goto end;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/start.c b/lttng/commands/start.c
> index 2eacc46..8139385 100644
> --- a/lttng/commands/start.c
> +++ b/lttng/commands/start.c
> @@ -33,11 +33,13 @@ static char *opt_session_name;
>  
>  enum {
>  	OPT_HELP = 1,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
>  	/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
> -	{"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"help",         'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"list-options", 0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -52,6 +54,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           Prints a simple list of options specific to start\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -111,6 +114,10 @@ int cmd_start(int argc, const char **argv)
>  			usage(stderr);
>  			ret = CMD_SUCCESS;
>  			goto end;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/stop.c b/lttng/commands/stop.c
> index 87862b4..0344d3b 100644
> --- a/lttng/commands/stop.c
> +++ b/lttng/commands/stop.c
> @@ -33,11 +33,13 @@ static char *opt_session_name;
>  
>  enum {
>  	OPT_HELP = 1,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
>  	/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
> -	{"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"help",         'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"list-options", 0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -52,6 +54,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           Prints a simple list of options specific to stop\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -109,6 +112,10 @@ int cmd_stop(int argc, const char **argv)
>  			usage(stderr);
>  			ret = CMD_SUCCESS;
>  			goto end;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/commands/version.c b/lttng/commands/version.c
> index 7b88523..3347382 100644
> --- a/lttng/commands/version.c
> +++ b/lttng/commands/version.c
> @@ -26,14 +26,17 @@
>  #include <unistd.h>
>  
>  #include "../cmd.h"
> +#include "../utils.h"
>  
>  enum {
>  	OPT_HELP = 1,
> +	OPT_LISTOPTS,
>  };
>  
>  static struct poptOption long_options[] = {
>  	/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
> -	{"help",      'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"help",         'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
> +	{"list-options", 0,   POPT_ARG_NONE, 0, OPT_LISTOPTS, 0, 0},
>  	{0, 0, 0, 0, 0, 0, 0}
>  };
>  
> @@ -45,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           Prints a simple list of options specific to version\n");
>  	fprintf(ofp, "\n");
>  }
>  
> @@ -65,6 +69,10 @@ int cmd_version(int argc, const char **argv)
>  			usage(stderr);
>  			ret = CMD_SUCCESS;
>  			goto end;
> +		case OPT_LISTOPTS:
> +			list_cmd_options(stdout, long_options);
> +			ret = CMD_SUCCESS;
> +			goto end;
>  		default:
>  			usage(stderr);
>  			ret = CMD_UNDEFINED;
> diff --git a/lttng/utils.c b/lttng/utils.c
> index ee0e297..b8f0bb9 100644
> --- a/lttng/utils.c
> +++ b/lttng/utils.c
> @@ -17,9 +17,11 @@
>   */
>  
>  #include <stdlib.h>
> +#include <ctype.h>
>  
>  #include <lttng/lttng.h>
>  
> +#include "utils.h"
>  #include "conf.h"
>  
>  /*
> @@ -77,3 +79,26 @@ int set_session_name(char *name)
>  error:
>  	return ret;
>  }
> +
> +/*
> + * 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);
> +		}
> +	}
> +}
> +
> diff --git a/lttng/utils.h b/lttng/utils.h
> index 5492d5e..e609b70 100644
> --- a/lttng/utils.h
> +++ b/lttng/utils.h
> @@ -19,8 +19,11 @@
>  #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 */
> -- 
> 1.7.4.1
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list