]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: add placeholder '0' to specify all columns
authorKarel Zak <kzak@redhat.com>
Mon, 10 May 2021 08:46:51 +0000 (10:46 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 10 May 2021 08:46:51 +0000 (10:46 +0200)
Fixes: https://github.com/karelzak/util-linux/issues/1306
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.1.adoc
text-utils/column.c

index aebcfb9496ef50ffb6f84bf793a2c7f528ebad85..10c8595419bf5927e59b1d5ab32a914431f3e63a 100644 (file)
@@ -65,7 +65,7 @@ Input is taken from _file_, or otherwise from standard input. Empty lines are ig
 
 == OPTIONS
 
-The argument _columns_ for *--table-** options is a comma separated list of the column names as defined by *--table-columns* or it's column number in order as specified by input. It's possible to mix names and numbers.
+The argument _columns_ for *--table-** options is a comma separated list of the column names as defined by *--table-columns* or it's column number in order as specified by input. It's possible to mix names and numbers. The special placeholder '0' (e.g. -R0) may be used to specify all columns.
 
 *-J, --json*::
 Use JSON output format to print the table, the option *--table-columns* is required and the option *--table-name* is recommended.
index 134b0b6ef69466757242680eca158069cc466c31..1bc90e84e3f766e1a718a785d439055ab05014fd 100644 (file)
@@ -278,13 +278,28 @@ static int column_set_flag(struct libscols_column *cl, int fl)
 static void apply_columnflag_from_list(struct column_control *ctl, const char *list,
                                         int flag, const char *errmsg)
 {
-       char **all = split_or_error(list, errmsg);
+       char **all;
        char **one;
        int unnamed = 0;
+       struct libscols_column *cl;
 
-       STRV_FOREACH(one, all) {
-               struct libscols_column *cl;
+       /* apply to all */
+       if (list && strcmp(list, "0") == 0) {
+               struct libscols_iter *itr;
+
+               itr = scols_new_iter(SCOLS_ITER_FORWARD);
+               if (!itr)
+                       err_oom();
 
+               while (scols_table_next_column(ctl->tab, itr, &cl) == 0)
+                       column_set_flag(cl, flag);
+               scols_free_iter(itr);
+       }
+
+       all = split_or_error(list, errmsg);
+
+       /* apply to columns specified by name */
+       STRV_FOREACH(one, all) {
                if (flag == SCOLS_FL_HIDDEN && strcmp(*one, "-") == 0) {
                        unnamed = 1;
                        continue;
@@ -298,7 +313,6 @@ static void apply_columnflag_from_list(struct column_control *ctl, const char *l
        /* apply flag to all columns without name */
        if (unnamed) {
                struct libscols_iter *itr;
-               struct libscols_column *cl;
 
                itr = scols_new_iter(SCOLS_ITER_FORWARD);
                if (!itr)