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>
OPT_HELP = 1,
OPT_TYPE,
OPT_USERSPACE,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
{"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}
};
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");
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;
OPT_FUNCTION_ENTRY,
OPT_SYSCALL,
OPT_USERSPACE,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
{"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}
};
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");
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;
#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}
};
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");
}
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;
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}
};
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");
}
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;
enum {
OPT_HELP = 1,
OPT_USERSPACE,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
#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}
};
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
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;
enum {
OPT_HELP = 1,
OPT_USERSPACE,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
#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}
};
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");
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;
OPT_SWITCH_TIMER,
OPT_READ_TIMER,
OPT_USERSPACE,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
{"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}
};
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
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;
OPT_SYSCALL,
OPT_USERSPACE,
OPT_TRACEPOINT_LOGLEVEL,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
#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}
};
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");
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;
enum {
OPT_HELP = 1,
OPT_USERSPACE,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
#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}
};
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
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;
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}
};
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");
}
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;
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}
};
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");
}
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;
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}
};
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");
}
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;
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}
};
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");
}
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;
}
/*
- * 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;
}
}
}
/* 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;
}
*/
#include <stdlib.h>
+#include <ctype.h>
#include <common/error.h>
#include "conf.h"
+#include "utils.h"
/*
* get_session_name
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);
+ }
+ }
+}
#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 */