diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-06-12 15:37:53 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-06-13 14:20:03 +0200 |
commit | dcd5c891cb1627c1e68635cb04beda8a012e0532 (patch) | |
tree | efa61b52e92a60f733891e8fd778b3932c352950 /src/binfmt | |
parent | ba1dc1a12b2a114eb66045f472feb6ae544c9684 (diff) | |
download | systemd-dcd5c891cb1627c1e68635cb04beda8a012e0532.tar.gz |
binfmt,sysctl,sysuers,tmpfiles: add auto-paging for --cat-config commands
The output of these commands is really long, and already enriched with
color. Let's add auto-paging to make this easier to digest.
Diffstat (limited to 'src/binfmt')
-rw-r--r-- | src/binfmt/binfmt.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index 0eb9e46014..f4af4bef26 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -19,12 +19,14 @@ #include "fd-util.h" #include "fileio.h" #include "log.h" +#include "pager.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" #include "util.h" static bool arg_cat_config = false; +static bool arg_no_pager = false; static int delete_rule(const char *rule) { _cleanup_free_ char *x = NULL, *fn = NULL; @@ -104,6 +106,7 @@ static void help(void) { " -h --help Show this help\n" " --version Show package version\n" " --cat-config Show configuration files\n" + " --no-pager Do not pipe output into a pager\n" , program_invocation_short_name); } @@ -112,12 +115,14 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_VERSION = 0x100, ARG_CAT_CONFIG, + ARG_NO_PAGER, }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, ARG_VERSION }, - { "cat-config", no_argument, NULL, ARG_CAT_CONFIG }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "cat-config", no_argument, NULL, ARG_CAT_CONFIG }, + { "no-pager", no_argument, NULL, ARG_NO_PAGER }, {} }; @@ -141,6 +146,10 @@ static int parse_argv(int argc, char *argv[]) { arg_cat_config = true; break; + case ARG_NO_PAGER: + arg_no_pager = true; + break; + case '?': return -EINVAL; @@ -190,6 +199,8 @@ int main(int argc, char *argv[]) { } if (arg_cat_config) { + (void) pager_open(arg_no_pager, false); + r = cat_files(NULL, files, 0); goto finish; } @@ -205,5 +216,7 @@ int main(int argc, char *argv[]) { } finish: + pager_close(); + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } |