From fb3761809fa847cb0012f98c6614d5e8c1f8dbe2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 18 Mar 2019 16:58:41 +0100 Subject: lsblk: force tree on --json --tree independently on used columns Signed-off-by: Karel Zak --- misc-utils/lsblk.8 | 6 ++++-- misc-utils/lsblk.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'misc-utils') diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8 index 07cd7a16f..320158278 100644 --- a/misc-utils/lsblk.8 +++ b/misc-utils/lsblk.8 @@ -90,7 +90,8 @@ The filter is applied to the top-level devices only. This maybe be confusing for Use ASCII characters for tree formatting. .TP .BR \-J , " \-\-json" -Use JSON output format. +Use JSON output format. It's strongly recommended to use \fB\-\-output\fR and +also \fB\-\-tree\fR if necessary. .TP .BR \-l , " \-\-list" Produce output in the form of a list. The output does not provide information @@ -111,7 +112,8 @@ Do not print a header line. .BR \-o , " \-\-output " \fIlist\fP Specify which output columns to print. Use .B \-\-help -to get a list of all supported columns. +to get a list of all supported columns. The columns may affect tree-like output. +The default is to use tree for the column 'NAME' (see also \fB\-\-tree\fR). The default list of columns may be extended if \fIlist\fP is specified in the format \fI+list\fP (e.g. \fBlsblk -o +UUID\fP). diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 454f067c8..3e9b96a4d 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -2054,6 +2054,15 @@ int main(int argc, char *argv[]) if (lsblk->dedup_hidden && lsblk->dedup_id == id) fl |= SCOLS_FL_HIDDEN; + if (force_tree + && lsblk->flags & LSBLK_JSON + && has_tree_col == 0 + && i + 1 == ncolumns) + /* The "--tree --json" specified, but no column with + * SCOLS_FL_TREE yet; force it for the last column + */ + fl |= SCOLS_FL_TREE; + cl = scols_table_new_column(lsblk->table, ci->name, ci->whint, fl); if (!cl) { warn(_("failed to allocate output column")); -- cgit v1.2.3-55-g7522