From: Philippe Proulx Date: Mon, 16 Nov 2015 03:35:03 +0000 (-0500) Subject: lttng add-context: add --list option X-Git-Tag: v2.8.0-rc1~32 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=83cea427013b03a98811e88964f60b1f27bc4345;p=lttng-tools.git lttng add-context: add --list option Since --help is replaced by the command's man page, we need a place to get the list of available context types. The new --list option of add-context does this. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index a6d73a0a7..6f7c23c01 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -33,8 +33,6 @@ #include "../command.h" -#define PRINT_LINE_LEN 80 - static char *opt_channel_name; static char *opt_session_name; static int opt_kernel; @@ -50,6 +48,7 @@ enum { OPT_JUL, OPT_LOG4J, OPT_LIST_OPTIONS, + OPT_LIST, }; static struct lttng_handle *handle; @@ -157,6 +156,7 @@ static struct poptOption long_options[] = { {"jul", 'j', POPT_ARG_NONE, 0, OPT_JUL, 0, 0}, {"log4j", 'l', POPT_ARG_NONE, 0, OPT_LOG4J, 0, 0}, {"type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, 0, 0}, + {"list", 0, POPT_ARG_NONE, NULL, OPT_LIST, NULL, NULL}, {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, {0, 0, 0, 0, 0, 0, 0} }; @@ -480,25 +480,11 @@ struct ctx_type_list { */ static void print_ctx_type(FILE *ofp) { - const char *indent = " "; - int indent_len = strlen(indent); - int len, i = 0; + int i = 0; - fprintf(ofp, "%s", indent); - len = indent_len; while (ctx_opts[i].symbol != NULL) { if (!ctx_opts[i].hide_help) { - if (len > indent_len) { - if (len + strlen(ctx_opts[i].symbol) + 2 - >= PRINT_LINE_LEN) { - fprintf(ofp, ",\n"); - fprintf(ofp, "%s", indent); - len = indent_len; - } else { - len += fprintf(ofp, ", "); - } - } - len += fprintf(ofp, "%s", ctx_opts[i].symbol); + fprintf(ofp, "%s\n", ctx_opts[i].symbol); } i++; } @@ -857,6 +843,9 @@ int cmd_add_context(int argc, const char **argv) case OPT_HELP: usage(stdout); goto end; + case OPT_LIST: + print_ctx_type(stdout); + goto end; case OPT_TYPE: { type = get_context_type(opt_type);