1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 10:25:37 +03:00

path: add --no-pager option, enable pager by default

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-09-14 22:30:14 +02:00
parent c19c5aa5b3
commit e441d1d46e

View File

@ -12,10 +12,12 @@
#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;