]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsns: fix --list-columns option
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Tue, 2 Sep 2025 21:13:44 +0000 (17:13 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Tue, 2 Sep 2025 21:26:01 +0000 (17:26 -0400)
This patch makes it so that we continue parsing all CLI options even
when we find -H/--list-columns. Therefore we don't miss any format
specifying options, namely --json and --raw, and print the columns
in the desired form.

Closes: #3725
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
sys-utils/lsns.c

index 6b6ad8355c70acccfdc84c3162e624ab32fa40a2..074df806bf7a0555db68b3ac7aac49580091c18f 100644 (file)
@@ -1591,15 +1591,14 @@ static void __attribute__((__noreturn__)) usage(void)
        exit(EXIT_SUCCESS);
 }
 
-static void __attribute__((__noreturn__)) list_colunms(bool raw, bool json)
+static void __attribute__((__noreturn__)) list_colunms(struct lsns *ls)
 {
-   struct libscols_table *col_tb = xcolumn_list_table_new("lsns-columns", stdout, raw, json);
+   struct libscols_table *col_tb = xcolumn_list_table_new("lsns-columns", stdout, ls->raw, ls->json);
 
    for (size_t i = 0; i < ARRAY_SIZE(infos); i++)
            xcolumn_list_table_append_line(col_tb, infos[i].name,
                                          infos[i].json_type, NULL,
                                          _(infos[i].help));
-
    scols_print_table(col_tb);
    scols_unref_table(col_tb);
 
@@ -1619,7 +1618,7 @@ static dev_t read_nsfs_dev(void)
 int main(int argc, char *argv[])
 {
        struct lsns ls;
-       int c, force_list = 0;
+       int c, force_list = 0, collist = 0;
        int r = 0;
        char *outarg = NULL;
        enum {
@@ -1731,8 +1730,8 @@ int main(int argc, char *argv[])
                        ls.filter = new_filter(optarg);
                        break;
                case 'H':
-                       list_colunms(ls.raw, ls.json);
-
+                       collist = 1;
+                       break;
                case 'h':
                        usage();
                case 'V':
@@ -1742,6 +1741,9 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (collist)
+               list_colunms(&ls);
+
        if (!ls.fltr_ntypes) {
                size_t i;