diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index ef90e62a00..9d70999545 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3,17 +3,16 @@ #include #include +#include "sd-json.h" + #include "argv-util.h" #include "build.h" #include "bus-print-properties.h" #include "bus-util.h" #include "capsule-util.h" #include "extract-word.h" -#include "format-table.h" -#include "help-util.h" #include "image-policy.h" #include "install.h" -#include "options.h" #include "output-mode.h" #include "pager.h" #include "parse-argument.h" @@ -112,58 +111,13 @@ STATIC_DESTRUCTOR_REGISTER(arg_drop_in, unsetp); STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep); STATIC_DESTRUCTOR_REGISTER(arg_kill_subgroup, freep); -static int systemctl_help(void) { - static const char *const vgroups[] = { - "Unit Commands", - "Unit File Commands", - "Machine Commands", - "Job Commands", - "Environment Commands", - "Manager State Commands", - "System Commands", - }; - - Table *vtables[ELEMENTSOF(vgroups)] = {}; - CLEANUP_ELEMENTS(vtables, table_unref_array_clear); - _cleanup_(table_unrefp) Table *options_table = NULL; - int r; - - for (size_t i = 0; i < ELEMENTSOF(vgroups); i++) { - r = verbs_get_help_table_group(vgroups[i], &vtables[i]); - if (r < 0) - return r; - } - - r = option_parser_get_help_table_ns("systemctl", &options_table); - if (r < 0) - return r; - - assert_cc(ELEMENTSOF(vtables) == 7); - (void) table_sync_column_widths(0, options_table, - vtables[0], vtables[1], vtables[2], vtables[3], - vtables[4], vtables[5], vtables[6]); - - pager_open(arg_pager_flags); - - help_cmdline("[OPTIONS…] COMMAND …"); - help_abstract("Query or send control commands to the system manager."); - - for (size_t i = 0; i < ELEMENTSOF(vgroups); i++) { - help_section(vgroups[i]); - r = table_print_or_warn(vtables[i]); - if (r < 0) - return r; - } - - help_section("Options"); - r = table_print_or_warn(options_table); - if (r < 0) - return r; - - help_man_page_reference("systemctl", "1"); - - return 0; -} +COMMAND( + "systemctl\0", + "Query or send control commands to the system manager.", + .man_pages = "systemctl.1\0", + .option_namespace = "systemctl", + .pager_flags = &arg_pager_flags, +); static int parse_property_argument(const char *value, char ***properties) { int r; @@ -397,7 +351,7 @@ static int systemctl_parse_argv(int argc, char *argv[], int log_level_shift, cha OPTION_NAMESPACE("systemctl"): {} OPTION_COMMON_HELP: - return systemctl_help(); + return command_print_help_full("systemctl"); OPTION_COMMON_VERSION: return version(); @@ -880,6 +834,9 @@ static int systemctl_parse_argv(int argc, char *argv[], int log_level_shift, cha " %s [OPTIONS…] COMMAND -- -.%s …", program_invocation_name, opts.arg ?: "mount"); return -EINVAL; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } /* If we are in --user mode, there's no point in talking to PolicyKit or the infra to query system diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index 4a7d61cae3..284182fcfe 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -34,6 +34,7 @@ INTROSPECTABLE=( run0 scsi_id storagectl + systemctl systemd-ac-power systemd-analyze systemd-ask-password @@ -138,6 +139,9 @@ for i in "${INTROSPECTABLE[@]}"; do # If the tool has a "help" verb, it must work too if $i --introspect-cli | jq -e 'any(.commands[]; (.verbs // []) | any(.names[0] == "help"))' >/dev/null; then + # 'systemctl help' shows unit manuals + [[ "$i" == systemctl ]] && continue + $i help >/dev/null fi done