]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslocks: cleanup --list-columns
authorKarel Zak <kzak@redhat.com>
Wed, 6 Dec 2023 11:26:39 +0000 (12:26 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Dec 2023 11:35:51 +0000 (12:35 +0100)
* remove "Available columns" from --help
* remove dependence on command-line options order ("-H -J" vs. "-J -H")
* remove global variable shadowing for 'raw' and 'json'
* keep --list-columns in "help & version block" in usage() output

References: https://github.com/util-linux/util-linux/pull/2602
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lslocks.c

index ec298b2ec8e1bc21a828343fa3afa08be67929e5..2881855589b7f10eda1d9f5c379952cfabc578fe 100644 (file)
@@ -819,27 +819,22 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -J, --json             use JSON output format\n"), out);
        fputs(_(" -i, --noinaccessible   ignore locks without read permissions\n"), out);
        fputs(_(" -n, --noheadings       don't print headings\n"), out);
-       fputs(_(" -o, --output <list>    define which output columns to use\n"), out);
+       fputs(_(" -o, --output <list>    output columns (see --list-columns)\n"), out);
        fputs(_("     --output-all       output all columns\n"), out);
        fputs(_(" -p, --pid <pid>        display only locks held by this process\n"), out);
        fputs(_(" -r, --raw              use the raw output format\n"), out);
        fputs(_(" -u, --notruncate       don't truncate text in columns\n"), out);
-       fputs(_(" -H, --list-columns     list the available columns\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
+       fputs(_(" -H, --list-columns     list the available columns\n"), out);
        fprintf(out, USAGE_HELP_OPTIONS(24));
-
-       fputs(USAGE_COLUMNS, out);
-
        fprintf(out, USAGE_MAN_TAIL("lslocks(8)"));
 
        exit(EXIT_SUCCESS);
 }
 
 static void __attribute__((__noreturn__)) list_colunms(const char *table_name,
-                                                      FILE *out,
-                                                      int raw,
-                                                      int json)
+                                                      FILE *out)
 {
        struct libscols_table *col_tb = xcolumn_list_table_new(table_name, out, raw, json);
 
@@ -849,8 +844,7 @@ static void __attribute__((__noreturn__)) list_colunms(const char *table_name,
                        xcolumn_list_table_append_line(col_tb, infos[i].name,
                                                       json_type, NULL,
                                                       _(infos[i].help));
-               }
-               else
+               } else
                        xcolumn_list_table_append_line(col_tb, infos[i].name,
                                                       -1, "<string|number>",
                                                       _(infos[i].help));
@@ -864,7 +858,7 @@ static void __attribute__((__noreturn__)) list_colunms(const char *table_name,
 
 int main(int argc, char *argv[])
 {
-       int c, rc = 0;
+       int c, rc = 0, collist = 0;
        struct list_head proc_locks;
        void *pid_locks = NULL;
        char *outarg = NULL;
@@ -934,10 +928,11 @@ int main(int argc, char *argv[])
                        disable_columns_truncate();
                        break;
 
+               case 'H':
+                       collist = 1;
+                       break;
                case 'V':
                        print_version(EXIT_SUCCESS);
-               case 'H':
-                       list_colunms("lslocks-columns", stdout, raw, json);
                case 'h':
                        usage();
                default:
@@ -945,6 +940,9 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (collist)
+               list_colunms("lslocks-columns", stdout);        /* print end exit */
+
        INIT_LIST_HEAD(&proc_locks);
 
        if (!ncolumns) {