]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path: add --no-pager option, enable pager by default
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 14 Sep 2023 20:30:14 +0000 (22:30 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 14 Sep 2023 20:33:18 +0000 (22:33 +0200)
When called with no argument, to list all known values, it is likely that it's
used by somebody to look at all the whole list. The output is more than a page,
so let's enable the pager.

src/path/path.c

index a02047d1107c107ae01b51e5e807f8f5a95208af..9845425d01b5832ffbf9c3094c77cae82109ab62 100644 (file)
 #include "log.h"
 #include "macro.h"
 #include "main-func.h"
+#include "pager.h"
 #include "pretty-print.h"
 #include "string-util.h"
 
 static const char *arg_suffix = NULL;
+PagerFlags arg_pager_flags = 0;
 
 static const char* const path_table[_SD_PATH_MAX] = {
         [SD_PATH_TEMPORARY]                                   = "temporary",
@@ -104,6 +106,8 @@ static const char* const path_table[_SD_PATH_MAX] = {
 static int list_paths(void) {
         int r = 0;
 
+        pager_open(arg_pager_flags);
+
         for (size_t i = 0; i < ELEMENTSOF(path_table); i++) {
                 _cleanup_free_ char *p = NULL;
                 int q;
@@ -155,6 +159,7 @@ static int help(void) {
                "  -h --help             Show this help\n"
                "     --version          Show package version\n"
                "     --suffix=SUFFIX    Suffix to append to paths\n"
+               "     --no-pager         Do not pipe output into a pager\n"
                "\nSee the %s for details.\n",
                program_invocation_short_name,
                link);
@@ -166,12 +171,14 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_SUFFIX,
+                ARG_NO_PAGER,
         };
 
         static const struct option options[] = {
                 { "help",      no_argument,       NULL, 'h'           },
                 { "version",   no_argument,       NULL, ARG_VERSION   },
                 { "suffix",    required_argument, NULL, ARG_SUFFIX    },
+                { "no-pager",  no_argument,       NULL, ARG_NO_PAGER  },
                 {}
         };
 
@@ -194,6 +201,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_suffix = optarg;
                         break;
 
+                case ARG_NO_PAGER:
+                        arg_pager_flags |= PAGER_DISABLE;
+                        break;
+
                 case '?':
                         return -EINVAL;