summaryrefslogtreecommitdiffstats
path: root/misc-utils
diff options
context:
space:
mode:
authorKarel Zak2019-03-18 16:58:41 +0100
committerKarel Zak2019-03-18 16:58:41 +0100
commitfb3761809fa847cb0012f98c6614d5e8c1f8dbe2 (patch)
tree91d431dd20bb3a37e3ade3cb6211754099f32f34 /misc-utils
parentdocs: TODO lscpu --list-caches (diff)
downloadkernel-qcow2-util-linux-fb3761809fa847cb0012f98c6614d5e8c1f8dbe2.tar.gz
kernel-qcow2-util-linux-fb3761809fa847cb0012f98c6614d5e8c1f8dbe2.tar.xz
kernel-qcow2-util-linux-fb3761809fa847cb0012f98c6614d5e8c1f8dbe2.zip
lsblk: force tree on --json --tree independently on used columns
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/lsblk.86
-rw-r--r--misc-utils/lsblk.c9
2 files changed, 13 insertions, 2 deletions
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"));