shared/options: drop option_parser_get_help_table() and its wrappers

The hand-written help() functions were the only users of the
namespace+group help table builder, and they are all gone. The one
remaining caller in the verbs machinery is ported to
options_find_namespace() + options_get_help_table_group(), which
build the identical table.

Also drop OPTION_COMMON_INTROSPECT_CLI_ENTRY: it has no users, and
references the no-longer-existing _OPTION_ENTRY() macro, so it could
not even be used.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-28 14:50:10 +02:00
parent e348b263ce
commit e90de9e2db
3 changed files with 7 additions and 101 deletions
-80
View File
@@ -516,86 +516,6 @@ const Option* options_find_namespace(
return NULL; /* not found :/ */
}
int _option_parser_get_help_table_full(
const Option options[],
const Option options_end[],
const char *namespace,
const char *group,
Table **ret) {
int r;
// TODO: drop this function and all its wrappers
assert(ret);
_cleanup_(table_unrefp) Table *table = table_new("names", "help");
if (!table)
return log_oom();
bool in_ns = namespace == NULL; /* Are we currently in the section of the array that forms namespace
* <namespace>? The first part is the default unnamed namespace, so
* if the namespace was not specified, we are in it. */
bool in_group = group == NULL; /* Are we currently in the section of the array that forms group
* <group>? The first part is the default group, so if the group was
* not specified, we are in it. */
const Option *opt;
for (opt = options; opt < options_end; opt++) {
bool ns_marker = FLAGS_SET(opt->flags, OPTION_NAMESPACE_MARKER);
if (!in_ns) {
in_ns = ns_marker && streq(namespace, opt->long_code);
continue;
}
if (ns_marker)
break; /* End of namespace */
bool group_marker = FLAGS_SET(opt->flags, OPTION_GROUP_MARKER);
if (!in_group) {
in_group = group_marker && streq(group, opt->long_code);
continue;
}
if (group_marker)
break; /* End of group */
if (!opt->help)
/* No help string — we do not show the option */
continue;
_cleanup_free_ char *s = option_get_synopsis(opt, " ", /* show_metavar= */ true);
if (!s)
return log_oom();
/* We indent the option string by two spaces. We could set the minimum cell width and
* right-align for a similar result, but that'd be more work. This is only used for
* display. */
bool shift_left = opt->short_code != 0 || FLAGS_SET(opt->flags, OPTION_HELP_ENTRY_VERBATIM);
const char *prefix = shift_left ? " " : " ";
_cleanup_free_ char *t = strjoin(prefix, s);
if (!t)
return log_oom();
r = table_add_many(table, TABLE_STRING, t);
if (r < 0)
return table_log_add_error(r);
_cleanup_strv_free_ char **split = strv_split(opt->help, /* separators= */ NULL);
if (!split)
return log_oom();
r = table_add_many(table, TABLE_STRV_WRAPPED, split);
if (r < 0)
return table_log_add_error(r);
}
assert(!table_isempty(table)); /* The namespace or group were not found. Something is off. */
table_set_header(table, false);
*ret = TAKE_PTR(table);
assert(opt - options < INT_MAX);
return opt - options;
}
int options_get_help_table_group(
const Option options[],
const Option options_end[],
-19
View File
@@ -99,10 +99,6 @@ assert_cc(sizeof(Option) % sizeof(void*) == 0);
/* This option is internal-only for now and not shown in --help */ \
OPTION_LONG("introspect-cli", NULL, /* help= */ NULL)
/* For programs which do not do option parsing, but check the argv array directly. */
#define OPTION_COMMON_INTROSPECT_CLI_ENTRY \
_OPTION_ENTRY(__COUNTER__, /* fl= */ 0, /* sc= */ 0, "introspect-cli", /* mv= */ NULL, /* d= */ 0u, /* h= */ NULL)
#define OPTION_COMMON_NO_PAGER \
OPTION_LONG("no-pager", NULL, "Do not start a pager")
@@ -281,21 +277,6 @@ const Option* options_find_namespace(
const Option options_end[],
const char *namespace);
int _option_parser_get_help_table_full(
const Option options[],
const Option options_end[],
const char *namespace,
const char *group,
Table **ret);
#define option_parser_get_help_table_full(namespace, group, ret) \
_option_parser_get_help_table_full(__start_SYSTEMD_OPTIONS, __stop_SYSTEMD_OPTIONS, namespace, group, ret)
#define option_parser_get_help_table_ns(ns, ret) \
option_parser_get_help_table_full(ns, /* group= */ NULL, ret)
#define option_parser_get_help_table_group(group, ret) \
option_parser_get_help_table_full(/* namespace= */ NULL, group, ret)
#define option_parser_get_help_table(ret) \
option_parser_get_help_table_group(/* group= */ NULL, ret)
int options_get_help_table_group(
const Option options[],
const Option options_end[],
+7 -2
View File
@@ -617,9 +617,14 @@ int _command_print_verb_help(
}
if (verb->option_namespace) {
const Option *optns = options_find_namespace(options, options_end, verb->option_namespace);
if (!optns)
return log_error_errno(SYNTHETIC_ERRNO(EUCLEAN),
"Option namespace %s not found.", verb->option_namespace);
_cleanup_(table_unrefp) Table *table = NULL;
r = _option_parser_get_help_table_full(options, options_end, verb->option_namespace,
/* group= */ NULL, &table);
const char *group;
r = options_get_help_table_group(optns, options_end, /* option_groups= */ NULL, &table, &group);
if (r < 0)
return r;