]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: force tree on --json --tree independently on used columns
authorKarel Zak <kzak@redhat.com>
Mon, 18 Mar 2019 15:58:41 +0000 (16:58 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Mar 2019 15:58:41 +0000 (16:58 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.8
misc-utils/lsblk.c

index 07cd7a16fbbb1fdabde72cc9c39174bf939e9483..3201582789f892093fe8e33db186b1d17e517f52 100644 (file)
@@ -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 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
 .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
 .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).
 
 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).
index 454f067c82891e592c1fcbf0605cb06b3f4e6e90..3e9b96a4d51e94cccb14f6b36df0368ade55ea60 100644 (file)
@@ -2054,6 +2054,15 @@ int main(int argc, char *argv[])
                if (lsblk->dedup_hidden && lsblk->dedup_id == id)
                        fl |= SCOLS_FL_HIDDEN;
 
                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"));
                cl = scols_table_new_column(lsblk->table, ci->name, ci->whint, fl);
                if (!cl) {
                        warn(_("failed to allocate output column"));