mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
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().
This commit is contained in:
parent
a9e6803582
commit
1be6a5db21
@ -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>
|
||||
|
||||
|
@ -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" />
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user