Skip to contentSkip to conversation

Reorder functions _lttng_cmd_* functions in bash completion

PATCH New [email protected] 2 participants 5 messages Aug 13, 2013 – Aug 26, 2013 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/5 Reorder functions _lttng_cmd_* functions in bash completion

From: Simon Marchi <[email protected]>

Simply reorder them alphabetically to be consistent.

---
 extras/lttng-bash_completion |   68 ++++++++++++++++++++---------------------
 1 files changed, 33 insertions(+), 35 deletions(-)
extras/lttng-bash_completion +33 -35
index bff8df7..d5a58f3 100644
@@ -50,6 +50,17 @@ _lttng_cmd_addcontext() {
 	esac
 }
 
+_lttng_cmd_calibrate() {
+	local calibrate_opts
+	calibrate_opts=$(lttng calibrate --list-options)
+
+	case $cur in
+	-*)
+		COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
+		;;
+	esac
+}
+
 _lttng_cmd_create() {
 	local create_opts
 	create_opts=$(lttng create --list-options)
@@ -82,10 +93,9 @@ _lttng_cmd_destroy() {
 		;;
 	esac
 }
-
-_lttng_cmd_enablechannel() {
-	local enable_channel_opts
-	enable_channel_opts=$(lttng enable-channel --list-options)
+_lttng_cmd_disablechannel() {
+	local disable_channel_opts
+	disable_channel_opts=$(lttng disable-channel --list-options)
 
 	case $prev in
 	--session|-s)
@@ -96,15 +106,14 @@ _lttng_cmd_enablechannel() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
+		COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
 		return
 		;;
 	esac
 }
-
-_lttng_cmd_enableevent() {
-	local enable_event_opts
-	enable_event_opts=$(lttng enable-event --list-options)
+_lttng_cmd_disableevent() {
+	local disable_event_opts
+	disable_event_opts=$(lttng disable-event --list-options)
 
 	case $prev in
 	--session|-s)
@@ -114,25 +123,19 @@ _lttng_cmd_enableevent() {
 	--channel|-c)
 		return
 		;;
-	--probe)
-		return
-		;;
-	--function)
-		return
-		;;
 	esac
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
+		COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
 		return
 		;;
 	esac
 }
 
-_lttng_cmd_disablechannel() {
-	local disable_channel_opts
-	disable_channel_opts=$(lttng disable-channel --list-options)
+_lttng_cmd_enablechannel() {
+	local enable_channel_opts
+	enable_channel_opts=$(lttng enable-channel --list-options)
 
 	case $prev in
 	--session|-s)
@@ -143,15 +146,15 @@ _lttng_cmd_disablechannel() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
+		COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
 		return
 		;;
 	esac
 }
 
-_lttng_cmd_disableevent() {
-	local disable_event_opts
-	disable_event_opts=$(lttng disable-event --list-options)
+_lttng_cmd_enableevent() {
+	local enable_event_opts
+	enable_event_opts=$(lttng enable-event --list-options)
 
 	case $prev in
 	--session|-s)
@@ -161,11 +164,17 @@ _lttng_cmd_disableevent() {
 	--channel|-c)
 		return
 		;;
+	--probe)
+		return
+		;;
+	--function)
+		return
+		;;
 	esac
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
+		COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
 		return
 		;;
 	esac
@@ -247,17 +256,6 @@ _lttng_cmd_version() {
 	esac
 }
 
-_lttng_cmd_calibrate() {
-	local calibrate_opts
-	calibrate_opts=$(lttng calibrate --list-options)
-
-	case $cur in
-	-*)
-		COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
-		;;
-	esac
-}
-
 _lttng_cmd_view() {
 	local view_opts
 		view_opts=$(lttng view --list-options)
Signature · 1 line
1.7.1
#2 lore raw

PATCH 3/5 Add --list-commands option to the snapshot command

In reply to a message not in the archive

From: Simon Marchi <[email protected]>

It lists snapshot sub-commands. This involves moving list_commands to utils so that commands can use it.

---
 src/bin/lttng/commands/snapshot.c |    5 +++++
 src/bin/lttng/lttng.c             |   21 +--------------------
 src/bin/lttng/utils.c             |   19 +++++++++++++++++++
 src/bin/lttng/utils.h             |    3 +++
 4 files changed, 28 insertions(+), 20 deletions(-)
src/bin/lttng/commands/snapshot.c +5 -0
index 56acca8..7d49299 100644
@@ -49,6 +49,7 @@ enum {
 	OPT_HELP = 1,
 	OPT_LIST_OPTIONS,
 	OPT_MAX_SIZE,
+	OPT_LIST_COMMANDS,
 };
 
 static struct poptOption snapshot_opts[] = {
@@ -60,6 +61,7 @@ static struct poptOption snapshot_opts[] = {
 	{"name",         'n', POPT_ARG_STRING, &opt_output_name, 0, 0, 0},
 	{"max-size",     'm', POPT_ARG_DOUBLE, 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}
 };
 
@@ -439,6 +441,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:
 		{
 			long long int val;
src/bin/lttng/lttng.c +1 -20
index 5755db6..dc9dd92 100644
@@ -151,25 +151,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
  */
 static void clean_exit(int code)
@@ -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:
src/bin/lttng/utils.c +19 -0
index 6041655..e40c3fd 100644
@@ -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
src/bin/lttng/utils.h +3 -0
index 57bec12..fb973ca 100644
@@ -20,7 +20,10 @@
 
 #include <popt.h>
 
+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);
 
 /*
Signature · 1 line
1.7.1
#3 lore raw

PATCH 4/5 Update bash completion

In reply to a message not in the archive

From: Simon Marchi <[email protected]>

- Refactor options completion to remove a little bit of code duplication.
- Add subcommand completion for the snapshot command. It is not perfect, but it's a start.
- Add some comments to functions here and there.

---
 extras/lttng-bash_completion |  173 ++++++++++++++++++++++++++----------------
 1 files changed, 106 insertions(+), 67 deletions(-)
extras/lttng-bash_completion +106 -67
index d5a58f3..f5677e9 100644
@@ -15,6 +15,7 @@
 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 
+# Generates COMPREPLY with the existing session names
 _lttng_complete_sessions() {
 	# TODO
 	# This code does nothing for now. When there is a mecanism to get the
@@ -25,9 +26,18 @@ _lttng_complete_sessions() {
 	return
 }
 
+# Generates COMPREPLY with whatever is in the $options variable.
+_lttng_complete_options() {
+	COMPREPLY=( $(compgen -W "${options}" -- $cur) )
+}
+
+# Generates COMPREPLY with whatever is in the $commands variable.
+_lttng_complete_commands() {
+	COMPREPLY=( $(compgen -W "${commands}" -- $cur) )
+}
+
 _lttng_cmd_addcontext() {
-	local add_context_opts
-	add_context_opts=$(lttng add-context --list-options)
+	options=$(lttng add-context --list-options)
 
 	case $prev in
 	--session|-s)
@@ -44,26 +54,25 @@ _lttng_cmd_addcontext() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${add_context_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	esac
 }
 
 _lttng_cmd_calibrate() {
-	local calibrate_opts
-	calibrate_opts=$(lttng calibrate --list-options)
+	options=$(lttng calibrate --list-options)
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
+		_lttng_complete_options
+		return
 		;;
 	esac
 }
 
 _lttng_cmd_create() {
-	local create_opts
-	create_opts=$(lttng create --list-options)
+	options=$(lttng create --list-options)
 
 	case $prev in
 	--output|-o)
@@ -74,28 +83,28 @@ _lttng_cmd_create() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${create_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	esac
 }
 
 _lttng_cmd_destroy() {
-	local destroy_opts
-	destroy_opts=$(lttng destroy --list-options)
+	options=$(lttng destroy --list-options)
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${destroy_opts}" -- $cur) )
+		_lttng_complete_options
+		return
 		;;
 	*)
 		_lttng_complete_sessions
+		return
 		;;
 	esac
 }
 _lttng_cmd_disablechannel() {
-	local disable_channel_opts
-	disable_channel_opts=$(lttng disable-channel --list-options)
+	options=$(lttng disable-channel --list-options)
 
 	case $prev in
 	--session|-s)
@@ -106,14 +115,13 @@ _lttng_cmd_disablechannel() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	esac
 }
 _lttng_cmd_disableevent() {
-	local disable_event_opts
-	disable_event_opts=$(lttng disable-event --list-options)
+	options=$(lttng disable-event --list-options)
 
 	case $prev in
 	--session|-s)
@@ -127,15 +135,14 @@ _lttng_cmd_disableevent() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	esac
 }
 
 _lttng_cmd_enablechannel() {
-	local enable_channel_opts
-	enable_channel_opts=$(lttng enable-channel --list-options)
+	options=$(lttng enable-channel --list-options)
 
 	case $prev in
 	--session|-s)
@@ -146,15 +153,14 @@ _lttng_cmd_enablechannel() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	esac
 }
 
 _lttng_cmd_enableevent() {
-	local enable_event_opts
-	enable_event_opts=$(lttng enable-event --list-options)
+	options=$(lttng enable-event --list-options)
 
 	case $prev in
 	--session|-s)
@@ -174,15 +180,14 @@ _lttng_cmd_enableevent() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	esac
 }
 
 _lttng_cmd_list() {
-	local list_opts
-	list_opts=$(lttng list --list-options)
+	options=$(lttng list --list-options)
 
 	case $prev in
 	--channel|-c)
@@ -192,7 +197,7 @@ _lttng_cmd_list() {
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	*)
@@ -202,12 +207,11 @@ _lttng_cmd_list() {
 }
 
 _lttng_cmd_setsession() {
-	local set_session_opts
-	set_session_opts=$(lttng set-session --list-options)
+	options=$(lttng set-session --list-options)
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
+		_lttng_complete_options
 		return
 		;;
 	*)
@@ -217,27 +221,51 @@ _lttng_cmd_setsession() {
 	esac
 }
 
+_lttng_cmd_snapshot() {
+	options=$(lttng snapshot --list-options)
+	commands=$(lttng snapshot --list-commands)
+
+	_lttng_find_command $((command_found_index + 1))
+
+	if _lttng_cursor_is_after_command; then
+		case $prev in
+		--session|-s)
+			_lttng_complete_sessions
+			return
+			;;
+		esac
+
+		case $cur in
+		-*)
+			_lttng_complete_options
+			;;
+		esac
+	else
+		_lttng_complete_commands
+	fi
+}
+
 _lttng_cmd_start() {
-	local start_opts
-	start_opts=$(lttng start --list-options)
+	options=$(lttng start --list-options)
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${start_opts}" -- $cur) )
+		_lttng_complete_options
+		return
 		;;
 	*)
 		_lttng_complete_sessions
+		return
 		;;
 	esac
 }
 
 _lttng_cmd_stop() {
-	local stop_opts
-	stop_opts=$(lttng stop --list-options)
+	options=$(lttng stop --list-options)
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${stop_opts}" -- $cur) )
+		_lttng_complete_options
 		;;
 	*)
 		_lttng_complete_sessions
@@ -246,37 +274,26 @@ _lttng_cmd_stop() {
 }
 
 _lttng_cmd_version() {
-	local version_opts
-	version_opts=$(lttng version --list-options)
+	options=$(lttng version --list-options)
 
 	case $cur in
 	-*)
-		COMPREPLY=( $(compgen -W "${version_opts}" -- $cur) )
+		_lttng_complete_options
 		;;
 	esac
 }
 
 _lttng_cmd_view() {
-	local view_opts
-		view_opts=$(lttng view --list-options)
+	options=$(lttng view --list-options)
 
-		case $cur in
-		-*)
-		COMPREPLY=( $(compgen -W "${view_opts}" -- $cur) )
+	case $cur in
+	-*)
+		_lttng_complete_options
 		;;
 	esac
 }
 
-_lttng_opts() {
-	local opts
-	opts=$(lttng --list-options)
 
-	COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
-}
-
-_lttng_commands() {
-	COMPREPLY=( $(compgen -W "$commands" -- $cur) )
-}
 
 _lttng_before_command() {
 	# Check if the previous word should alter the behavior
@@ -294,11 +311,11 @@ _lttng_before_command() {
 	case $cur in
 	-*)
 		# If the current word starts with a dash, complete with options
-		_lttng_opts
+		_lttng_complete_options
 		;;
 	*)
 		# Otherwise complete with commands
-		_lttng_commands
+		_lttng_complete_commands
 		;;
 	esac
 }
@@ -306,11 +323,13 @@ _lttng_before_command() {
 _lttng_after_command() {
 	local cmd_name
 
-	cmd_name=_lttng_cmd_${command//-/}
+	cmd_name=_lttng_cmd_${command_found//-/}
 
 	type -t $cmd_name | grep -q 'function' && $cmd_name
 }
 
+# Check if the word passed as the first parameter corresponds to a
+# command. $command must be set to the list of possible commands.
 _lttng_is_command() {
 	for command in $commands; do
 		if [ "$1" == "$command" ]; then
@@ -321,14 +340,18 @@ _lttng_is_command() {
 	return 1
 }
 
-_lttng() {
-	local cur prev commands command_found command_found_index
-
-	# Get the current and previous word
-	_get_comp_words_by_ref cur prev
-
-	# Get the valid LTTng commands
-	commands=$(lttng --list-commands)
+# Try to find a command in the current command line. Possible commands
+# are passed in $commands.
+#
+# This function takes an optional parameter that indicates the index
+# where to start the search in COMP_WORDS. If omitted, it defaults to 1.
+#
+# If a command is found, $command_found is filled with the name of the
+# command and $command_found_index is set to the index of the command in
+# $COMP_WORDS. If no command is found, $command_found is an empty string
+# and $command_found_index is set to -1.
+_lttng_find_command() {
+	start=${1:-1}
 
 	# The text of the found command
 	command_found=""
@@ -336,18 +359,34 @@ _lttng() {
 	# The index of the found command in COMP_WORDS
 	command_found_index=-1
 
-	for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do
+	for (( i = start ; i < ${#COMP_WORDS[@]} ; i++ )); do
 		_lttng_is_command ${COMP_WORDS[$i]}
 		if [ $? -eq 0 ]; then
 			command_found=${COMP_WORDS[$i]}
 			command_found_index=$i
 			break
 		fi
-
 	done
+}
+
+_lttng_cursor_is_after_command() {
+	[ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]
+}
+
+_lttng() {
+	local cur prev commands command_found command_found_index
+
+	# Get the current and previous word
+	_get_comp_words_by_ref cur prev
+
+	# Get the valid first-level LTTng commands and options
+	commands=$(lttng --list-commands)
+	options=$(lttng --list-options)
+
+	_lttng_find_command
 
 	# Check if the cursor is before or after the command keyword
-	if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
+	if _lttng_cursor_is_after_command; then
 		_lttng_after_command
 	else
 		_lttng_before_command
Signature · 1 line
1.7.1
#4 lore raw

PATCH 5/5 Add session name completion in bash completion

In reply to a message not in the archive

From: Simon Marchi <[email protected]>

---
 extras/lttng-bash_completion |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
extras/lttng-bash_completion +1 -5
index f5677e9..5800a0e 100644
@@ -17,11 +17,7 @@
 
 # Generates COMPREPLY with the existing session names
 _lttng_complete_sessions() {
-	# TODO
-	# This code does nothing for now. When there is a mecanism to get the
-	# existing sessions, use it to fill the sessions variable.
-	local sessions
-	sessions=""
+	sessions=$(lttng list --mi)
 	COMPREPLY=( $(compgen -W "${sessions}" -- $cur) )
 	return
 }
Signature · 1 line
1.7.1
#5 lore raw

Re: [PATCH lttng-tools 1/5] Add --mi option to the list command

In reply to a message not in the archive

Like we spoke the other day on IRC, the --mi patch needs more work for the output format so we come up with something standard and documented.

So I've merged the 3 other patches that do not uses --mi option.

Cheers!
David

[email protected]:

Quoted 113 lines

From: Simon Marchi <[email protected]>

The --mi option is used to ask lttng to print information in a format easily understandable by another program. Currently, only session printing is affected: it prints session names one per line.

The term mi stands for machine interface, and is stolen without any remorse from GDB's lexicon.

---
 src/bin/lttng/commands/list.c |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)
src/bin/lttng/commands/list.c +26 -9
index 1c7085d..9e13e6b 100644
@@ -30,6 +30,7 @@ static int opt_kernel;
 static char *opt_channel;
 static int opt_domain;
 static int opt_fields;
+static int opt_mi;
 #if 0
 /* Not implemented yet */
 static char *opt_cmd_name;
@@ -44,6 +45,7 @@ enum {
 	OPT_HELP = 1,
 	OPT_USERSPACE,
 	OPT_LIST_OPTIONS,
+	OPT_MI,
 };
 
 static struct lttng_handle *handle;
@@ -63,6 +65,7 @@ static struct poptOption long_options[] = {
 	{"domain",    'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
 	{"fields",    'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
 	{"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
+	{"mi", 0, POPT_ARG_NONE, &opt_mi, 0, NULL, NULL},
 	{0, 0, 0, 0, 0, 0, 0}
 };
 
@@ -80,6 +83,7 @@ static void usage(FILE *ofp)
 	fprintf(ofp, "\n");
 	fprintf(ofp, "  -h, --help              Show this help\n");
 	fprintf(ofp, "      --list-options      Simple listing of options\n");
+	fprintf(ofp, "      --mi                Prints data in a format suitable for parsing\n");
 	fprintf(ofp, "  -k, --kernel            Select kernel domain\n");
 	fprintf(ofp, "  -u, --userspace         Select user-space domain.\n");
 	fprintf(ofp, "  -f, --fields            List event fields.\n");
@@ -618,40 +622,53 @@ static int list_sessions(const char *session_name)
 		ERR("%s", lttng_strerror(ret));
 		goto error;
 	} else if (count == 0) {
-		MSG("Currently no available tracing session");
+		if (!opt_mi) {
+			MSG("Currently no available tracing session");
+		}
 		goto end;
 	}
 
-	if (session_name == NULL) {
+	if (session_name == NULL && !opt_mi) {
 		MSG("Available tracing sessions:");
 	}
 
 	for (i = 0; i < count; i++) {
+
 		if (session_name != NULL) {
 			if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
 				session_found = 1;
-				MSG("Tracing session %s: [%s%s]", session_name,
+
+				if (opt_mi) {
+					MSG("%s", session_name);
+				} else {
+					MSG("Tracing session %s: [%s%s]", session_name,
 						active_string(sessions[i].enabled),
 						snapshot_string(sessions[i].snapshot_mode));
-				MSG("%sTrace path: %s\n", indent4, sessions[i].path);
+					MSG("%sTrace path: %s\n", indent4, sessions[i].path);
+				}
+
 				break;
 			}
 		} else {
-			MSG("  %d) %s (%s) [%s%s]", i + 1, sessions[i].name, sessions[i].path,
-					active_string(sessions[i].enabled),
-					snapshot_string(sessions[i].snapshot_mode));
+			if (opt_mi) {
+				MSG("%s", sessions[i].name);
+			} else {
+				MSG("  %d) %s (%s) [%s%s]", i + 1, sessions[i].name, sessions[i].path,
+						active_string(sessions[i].enabled),
+						snapshot_string(sessions[i].snapshot_mode));
+			}
 		}
 	}
 
 	free(sessions);
 
-	if (!session_found && session_name != NULL) {
+	if (!session_found && session_name != NULL && !opt_mi) {
 		ERR("Session '%s' not found", session_name);
 		ret = CMD_ERROR;
 		goto error;
 	}
 
-	if (session_name == NULL) {
+	if (session_name == NULL && !opt_mi) {
 		MSG("\nUse lttng list <session_name> for more details");
 	}