sysctl: convert to VERB_COMMAND and add --introspect-cli
The custom help() is replaced by a COMMAND() description, and --introspect-cli is added. An explicit "Commands" option group is added so that the section heading stays the same. The abstract is changed to the imperative. --help now goes through the pager, like other commands with --no-pager.
This commit is contained in:
+17
-46
@@ -1,26 +1,26 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
#include "conf-files.h"
|
||||
#include "constants.h"
|
||||
#include "creds-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "format-table.h"
|
||||
#include "glob-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "options.h"
|
||||
#include "pager.h"
|
||||
#include "path-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "sysctl-util.h"
|
||||
#include "verbs.h"
|
||||
|
||||
static char **arg_prefixes = NULL;
|
||||
static CatFlags arg_cat_flags = CAT_CONFIG_OFF;
|
||||
@@ -31,6 +31,14 @@ static PagerFlags arg_pager_flags = 0;
|
||||
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_prefixes, strv_freep);
|
||||
|
||||
COMMAND(
|
||||
"systemd-sysctl\0",
|
||||
"Apply kernel sysctl settings.",
|
||||
.argspec = "[CONFIGURATION FILE…]\0",
|
||||
.man_pages = "systemd-sysctl.service.8\0",
|
||||
.pager_flags = &arg_pager_flags,
|
||||
);
|
||||
|
||||
typedef struct SysctlOption {
|
||||
char *key;
|
||||
char *value;
|
||||
@@ -317,48 +325,6 @@ static int cat_config(char **files) {
|
||||
return cat_files(NULL, files, arg_cat_flags);
|
||||
}
|
||||
|
||||
static int help(void) {
|
||||
_cleanup_free_ char *link = NULL;
|
||||
_cleanup_(table_unrefp) Table *commands = NULL, *options = NULL;
|
||||
int r;
|
||||
|
||||
r = terminal_urlify_man("systemd-sysctl.service", "8", &link);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
r = option_parser_get_help_table(&commands);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = option_parser_get_help_table_group("Options", &options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) table_sync_column_widths(0, commands, options);
|
||||
|
||||
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n"
|
||||
"\n%sApplies kernel sysctl settings.%s\n"
|
||||
"\n%sCommands:%s\n",
|
||||
program_invocation_short_name,
|
||||
ansi_highlight(),
|
||||
ansi_normal(),
|
||||
ansi_underline(),
|
||||
ansi_normal());
|
||||
|
||||
r = table_print_or_warn(commands);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
printf("\n%sOptions:%s\n", ansi_underline(), ansi_normal());
|
||||
|
||||
r = table_print_or_warn(options);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
printf("\nSee the %s for details.\n", link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_argv(int argc, char *argv[], char ***remaining_args) {
|
||||
assert(argc >= 0);
|
||||
assert(argv);
|
||||
@@ -369,8 +335,10 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) {
|
||||
FOREACH_OPTION_OR_RETURN(c, &opts)
|
||||
switch (c) {
|
||||
|
||||
OPTION_GROUP("Commands"): {}
|
||||
|
||||
OPTION_COMMON_HELP:
|
||||
return help();
|
||||
return command_print_help("systemd-sysctl");
|
||||
|
||||
OPTION_COMMON_VERSION:
|
||||
return version();
|
||||
@@ -422,6 +390,9 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) {
|
||||
"Treat arguments as configuration lines"):
|
||||
arg_inline = true;
|
||||
break;
|
||||
|
||||
OPTION_COMMON_INTROSPECT_CLI:
|
||||
return introspect_cli(SD_JSON_FORMAT_OFF);
|
||||
}
|
||||
|
||||
*remaining_args = option_parser_get_args(&opts);
|
||||
|
||||
@@ -87,6 +87,7 @@ INTROSPECTABLE=(
|
||||
systemd-storage-block
|
||||
systemd-storage-fs
|
||||
systemd-storagetm
|
||||
systemd-sysctl
|
||||
systemd-sysinstall
|
||||
systemd-tpm2-clear
|
||||
systemd-tpm2-setup
|
||||
|
||||
Reference in New Issue
Block a user