From: Lennart Poettering Date: Fri, 24 Apr 2026 06:10:43 +0000 (+0200) Subject: ac-power,notify,systemctl: port 3 tools over to new --help APIs X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=44c8bce3a04dff4013f35e80764cde85f79d4ee9;p=thirdparty%2Fsystemd.git ac-power,notify,systemctl: port 3 tools over to new --help APIs Let's port over a few tools, to showcase the new logic. --- diff --git a/src/ac-power/ac-power.c b/src/ac-power/ac-power.c index dad4384ada7..e773d8d4314 100644 --- a/src/ac-power/ac-power.c +++ b/src/ac-power/ac-power.c @@ -1,14 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "alloc-util.h" -#include "ansi-color.h" #include "battery-util.h" #include "build.h" #include "format-table.h" +#include "help-util.h" #include "log.h" #include "main-func.h" #include "options.h" -#include "pretty-print.h" #include "string-util.h" static bool arg_verbose = false; @@ -19,29 +17,22 @@ static enum { } arg_action = ACTION_AC_POWER; static int help(void) { - _cleanup_free_ char *link = NULL; - _cleanup_(table_unrefp) Table *options = NULL; int r; - r = terminal_urlify_man("systemd-ac-power", "1", &link); - if (r < 0) - return log_oom(); - + _cleanup_(table_unrefp) Table *options = NULL; r = option_parser_get_help_table(&options); if (r < 0) return r; - printf("%s [OPTIONS...]\n" - "\n%sReport whether we are connected to an external power source.%s\n" - "\nOptions:\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal()); + help_cmdline("[OPTIONS...]"); + help_abstract("Report whether we are connected to an external power source."); + + help_section("Options:"); r = table_print_or_warn(options); if (r < 0) return r; - printf("\nSee the %s for details.\n", link); + help_man_page_reference("systemd-ac-power", "1"); return 0; } diff --git a/src/notify/notify.c b/src/notify/notify.c index 2ac0129bae1..d3201c66bcf 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -17,13 +17,13 @@ #include "fdset.h" #include "format-table.h" #include "format-util.h" +#include "help-util.h" #include "log.h" #include "main-func.h" #include "notify-recv.h" #include "options.h" #include "parse-util.h" #include "pidref.h" -#include "pretty-print.h" #include "process-util.h" #include "signal-util.h" #include "string-util.h" @@ -57,31 +57,24 @@ STATIC_DESTRUCTOR_REGISTER(arg_fds, fdset_freep); STATIC_DESTRUCTOR_REGISTER(arg_fdname, freep); static int help(void) { - _cleanup_free_ char *link = NULL; - _cleanup_(table_unrefp) Table *options = NULL; int r; - r = terminal_urlify_man("systemd-notify", "1", &link); - if (r < 0) - return log_oom(); - + _cleanup_(table_unrefp) Table *options = NULL; r = option_parser_get_help_table(&options); if (r < 0) return r; - printf("%1$s [OPTIONS...] [VARIABLE=VALUE...]\n" - "%1$s [OPTIONS...] --exec [VARIABLE=VALUE...] ; -- CMDLINE...\n" - "%1$s [OPTIONS...] --fork -- CMDLINE...\n" - "\n%2$sNotify the init system about service status updates.%3$s\n\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal()); + help_cmdline("[OPTIONS...] [VARIABLE=VALUE...]"); + help_cmdline("[OPTIONS...] --exec [VARIABLE=VALUE...] ; -- CMDLINE..."); + help_cmdline("[OPTIONS...] --fork -- CMDLINE..."); + help_abstract("Notify the init system about service status updates."); + help_section("Options:"); r = table_print_or_warn(options); if (r < 0) return r; - printf("\nSee the %s for details.\n", link); + help_man_page_reference("systemd-notify", "1"); return 0; } diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index e5e7b412f56..4f76c515002 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -10,6 +10,7 @@ #include "bus-util.h" #include "capsule-util.h" #include "extract-word.h" +#include "help-util.h" #include "image-policy.h" #include "install.h" #include "output-mode.h" @@ -17,7 +18,6 @@ #include "parse-argument.h" #include "parse-util.h" #include "path-util.h" -#include "pretty-print.h" #include "static-destruct.h" #include "string-table.h" #include "string-util.h" @@ -108,19 +108,13 @@ STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep); STATIC_DESTRUCTOR_REGISTER(arg_kill_subgroup, freep); static int systemctl_help(void) { - _cleanup_free_ char *link = NULL; - int r; - pager_open(arg_pager_flags); - r = terminal_urlify_man("systemctl", "1", &link); - if (r < 0) - return log_oom(); + help_cmdline("[OPTIONS...] COMMAND ..."); + help_abstract("Query or send control commands to the system manager."); - printf("%1$s [OPTIONS...] COMMAND ...\n\n" - "%5$sQuery or send control commands to the system manager.%6$s\n" - "\n%3$sUnit Commands:%4$s\n" - " list-units [PATTERN...] List units currently in memory\n" + help_section("Unit Commands:"); + printf(" list-units [PATTERN...] List units currently in memory\n" " list-automounts [PATTERN...] List automount units currently in memory,\n" " ordered by path\n" " list-paths [PATTERN...] List path units currently in memory,\n" @@ -166,9 +160,10 @@ static int systemctl_help(void) { " reset-failed [PATTERN...] Reset failed state for all, one, or more\n" " units\n" " whoami [PID...] Return unit caller or specified PIDs are\n" - " part of\n" - "\n%3$sUnit File Commands:%4$s\n" - " list-unit-files [PATTERN...] List installed unit files\n" + " part of\n"); + + help_section("Unit File Commands:"); + printf(" list-unit-files [PATTERN...] List installed unit files\n" " enable [UNIT...|PATH...] Enable one or more unit files\n" " disable UNIT... Disable one or more unit files\n" " reenable UNIT... Reenable one or more unit files\n" @@ -189,25 +184,30 @@ static int systemctl_help(void) { " on specified one or more units\n" " edit UNIT... Edit one or more unit files\n" " get-default Get the name of the default target\n" - " set-default TARGET Set the default target\n" - "\n%3$sMachine Commands:%4$s\n" - " list-machines [PATTERN...] List local containers and host\n" - "\n%3$sJob Commands:%4$s\n" - " list-jobs [PATTERN...] List jobs\n" - " cancel [JOB...] Cancel all, one, or more jobs\n" - "\n%3$sEnvironment Commands:%4$s\n" - " show-environment Dump environment\n" + " set-default TARGET Set the default target\n"); + + help_section("Machine Commands:"); + printf(" list-machines [PATTERN...] List local containers and host\n"); + + help_section("Job Commands:"); + printf(" list-jobs [PATTERN...] List jobs\n" + " cancel [JOB...] Cancel all, one, or more jobs\n"); + + help_section("Environment Commands:"); + printf(" show-environment Dump environment\n" " set-environment VARIABLE=VALUE... Set one or more environment variables\n" " unset-environment VARIABLE... Unset one or more environment variables\n" - " import-environment VARIABLE... Import all or some environment variables\n" - "\n%3$sManager State Commands:%4$s\n" - " daemon-reload Reload systemd manager configuration\n" + " import-environment VARIABLE... Import all or some environment variables\n"); + + help_section("Manager State Commands:"); + printf(" daemon-reload Reload systemd manager configuration\n" " daemon-reexec Reexecute systemd manager\n" " log-level [LEVEL] Get/set logging threshold for manager\n" " log-target [TARGET] Get/set logging target for manager\n" - " service-watchdogs [BOOL] Get/set service watchdog state\n" - "\n%3$sSystem Commands:%4$s\n" - " is-system-running Check whether system is fully running\n" + " service-watchdogs [BOOL] Get/set service watchdog state\n"); + + help_section("System Commands:"); + printf(" is-system-running Check whether system is fully running\n" " default Enter system default mode\n" " rescue Enter system rescue mode\n" " emergency Enter system emergency mode\n" @@ -224,9 +224,10 @@ static int systemctl_help(void) { " hibernate Hibernate the system\n" " hybrid-sleep Hibernate and suspend the system\n" " suspend-then-hibernate Suspend the system, wake after a period of\n" - " time, and hibernate" - "\n%3$sOptions:%4$s\n" - " -h --help Show this help\n" + " time, and hibernate\n"); + + help_section("Options:"); + printf(" -h --help Show this help\n" " --version Show package version\n" " --system Connect to system manager\n" " --user Connect to user service manager\n" @@ -319,14 +320,9 @@ static int systemctl_help(void) { " --drop-in=NAME Edit unit files using the specified drop-in file name\n" " --when=TIME Schedule halt/power-off/reboot/kexec action after\n" " a certain timestamp\n" - " --stdin Read new contents of edited file from stdin\n" - "\nSee the %2$s for details.\n", - program_invocation_short_name, - link, - ansi_underline(), - ansi_normal(), - ansi_highlight(), - ansi_normal()); + " --stdin Read new contents of edited file from stdin\n"); + + help_man_page_reference("systemctl", "1"); return 0; }