diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-10-15 18:33:10 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-10-24 18:32:17 +0200 |
commit | 1be6a5db21bfc785e201f32d56765d408428644e (patch) | |
tree | 173f1e685a05b655ec73a1a476f9162039328d69 | |
parent | shared/pretty-print: add highlighting (diff) | |
download | systemd-1be6a5db21bfc785e201f32d56765d408428644e.tar.xz systemd-1be6a5db21bfc785e201f32d56765d408428644e.zip |
tmpfiles: add --tldr
This is like --cat-config, but omits the comments and empty lines.
The name is incoungrous with --cat-config, but I don't see a nice way to
call it that wouldn't be annoyingly long.
pager_open() is moved to cat_config() to remove some lines from run().
-rw-r--r-- | man/standard-options.xml | 10 | ||||
-rw-r--r-- | man/systemd-tmpfiles.xml | 1 | ||||
-rw-r--r-- | src/shared/pretty-print.h | 6 | ||||
-rw-r--r-- | src/tmpfiles/tmpfiles.c | 30 |
4 files changed, 33 insertions, 14 deletions
diff --git a/man/standard-options.xml b/man/standard-options.xml index 75e91862f4..eb27f5cb65 100644 --- a/man/standard-options.xml +++ b/man/standard-options.xml @@ -74,6 +74,16 @@ </listitem> </varlistentry> + <varlistentry id='tldr'> + <term><option>--tldr</option></term> + + <listitem> + <para>Copy the contents of config files to standard output. Only the "interesting" parts of the + configuration files are printed, comments and empty lines are skipped. Before each file, the filename + is printed as a comment.</para> + </listitem> + </varlistentry> + <varlistentry id='json'> <term><option>--json=</option><replaceable>MODE</replaceable></term> diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml index c048927882..95e1e2951c 100644 --- a/man/systemd-tmpfiles.xml +++ b/man/systemd-tmpfiles.xml @@ -250,6 +250,7 @@ </varlistentry> <xi:include href="standard-options.xml" xpointer="cat-config" /> + <xi:include href="standard-options.xml" xpointer="tldr" /> <xi:include href="standard-options.xml" xpointer="no-pager" /> <xi:include href="standard-options.xml" xpointer="help" /> <xi:include href="standard-options.xml" xpointer="version" /> diff --git a/src/shared/pretty-print.h b/src/shared/pretty-print.h index aef74cac2f..b25684aaa6 100644 --- a/src/shared/pretty-print.h +++ b/src/shared/pretty-print.h @@ -15,8 +15,10 @@ int terminal_urlify_path(const char *path, const char *text, char **ret); int terminal_urlify_man(const char *page, const char *section, char **ret); typedef enum CatFlags { - CAT_FORMAT_HAS_SECTIONS = 1 << 0, /* Sections are meaningful for this file format */ - CAT_TLDR = 1 << 1, /* Only print comments and relevant section headers */ + CAT_CONFIG_OFF = 0, + CAT_CONFIG_ON = 1 << 0, + CAT_FORMAT_HAS_SECTIONS = 1 << 1, /* Sections are meaningful for this file format */ + CAT_TLDR = 1 << 2, /* Only print comments and relevant section headers */ } CatFlags; int cat_files(const char *file, char **dropins, CatFlags flags); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index aab65f49d1..818d3517e0 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -196,7 +196,7 @@ typedef enum { _CREATION_MODE_INVALID = -EINVAL, } CreationMode; -static bool arg_cat_config = false; +static CatFlags arg_cat_flags = CAT_CONFIG_OFF; static RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM; static OperationMask arg_operation = 0; static bool arg_boot = false; @@ -3936,7 +3936,9 @@ static int cat_config(char **config_dirs, char **args) { if (r < 0) return r; - return cat_files(NULL, files, 0); + pager_open(arg_pager_flags); + + return cat_files(NULL, files, arg_cat_flags); } static int exclude_default_prefixes(void) { @@ -3974,6 +3976,7 @@ static int help(void) { " --user Execute user configuration\n" " --version Show package version\n" " --cat-config Show configuration files\n" + " --tldr Show non-comment parts of configuration\n" " --create Create marked files/directories\n" " --clean Clean up marked directories\n" " --remove Remove marked files/directories\n" @@ -4001,6 +4004,7 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_VERSION = 0x100, ARG_CAT_CONFIG, + ARG_TLDR, ARG_USER, ARG_CREATE, ARG_CLEAN, @@ -4021,6 +4025,7 @@ static int parse_argv(int argc, char *argv[]) { { "user", no_argument, NULL, ARG_USER }, { "version", no_argument, NULL, ARG_VERSION }, { "cat-config", no_argument, NULL, ARG_CAT_CONFIG }, + { "tldr", no_argument, NULL, ARG_TLDR }, { "create", no_argument, NULL, ARG_CREATE }, { "clean", no_argument, NULL, ARG_CLEAN }, { "remove", no_argument, NULL, ARG_REMOVE }, @@ -4052,7 +4057,11 @@ static int parse_argv(int argc, char *argv[]) { return version(); case ARG_CAT_CONFIG: - arg_cat_config = true; + arg_cat_flags = CAT_CONFIG_ON; + break; + + case ARG_TLDR: + arg_cat_flags = CAT_TLDR; break; case ARG_USER: @@ -4140,17 +4149,17 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached(); } - if (arg_operation == 0 && !arg_cat_config) + if (arg_operation == 0 && arg_cat_flags == CAT_CONFIG_OFF) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "You need to specify at least one of --clean, --create or --remove."); + "You need to specify at least one of --clean, --create, or --remove."); - if (arg_replace && arg_cat_config) + if (arg_replace && arg_cat_flags != CAT_CONFIG_OFF) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Option --replace= is not supported with --cat-config"); + "Option --replace= is not supported with --cat-config/--tldr."); if (arg_replace && optind >= argc) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "When --replace= is given, some configuration items must be specified"); + "When --replace= is given, some configuration items must be specified."); if (arg_root && arg_runtime_scope == RUNTIME_SCOPE_USER) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), @@ -4455,11 +4464,8 @@ static int run(int argc, char *argv[]) { log_debug("Looking for configuration files in (higher priority first):%s", t); } - if (arg_cat_config) { - pager_open(arg_pager_flags); - + if (arg_cat_flags != CAT_CONFIG_OFF) return cat_config(config_dirs, argv + optind); - } umask(0022); |