cgls: convert to VERB_COMMAND and add --introspect-cli

The custom help() is replaced by a COMMAND() description, and
--introspect-cli is added. --help now goes through the pager, like other
commands with --no-pager.

Synopses are adjusted. --user-unit/--unit without any unit names is
technically allowed, but not very meaningful, since it's the same as
the default mode. So [] is dropped. And the prog help string is then
adjusted to match the man page.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-15 15:28:58 +02:00
parent 73d0a3a2ea
commit d768cdcceb
3 changed files with 15 additions and 31 deletions
+1 -1
View File
@@ -31,7 +31,7 @@
<command>systemd-cgls</command> <command>systemd-cgls</command>
<arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain"><option>--unit</option>|<option>--user-unit</option></arg> <arg choice="plain"><option>--unit</option>|<option>--user-unit</option></arg>
<arg choice="opt" rep="repeat">UNIT</arg> <arg choice="plain" rep="repeat">UNIT</arg>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
+13 -30
View File
@@ -3,25 +3,24 @@
#include <stdio.h> #include <stdio.h>
#include "sd-bus.h" #include "sd-bus.h"
#include "sd-json.h"
#include "alloc-util.h" #include "alloc-util.h"
#include "build.h" #include "build.h"
#include "bus-util.h" #include "bus-util.h"
#include "cgroup-show.h" #include "cgroup-show.h"
#include "cgroup-util.h" #include "cgroup-util.h"
#include "format-table.h"
#include "log.h" #include "log.h"
#include "main-func.h" #include "main-func.h"
#include "options.h"
#include "output-mode.h" #include "output-mode.h"
#include "pager.h" #include "pager.h"
#include "parse-util.h" #include "parse-util.h"
#include "path-util.h" #include "path-util.h"
#include "pretty-print.h"
#include "runtime-scope.h" #include "runtime-scope.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h" #include "strv.h"
#include "unit-name.h" #include "unit-name.h"
#include "verbs.h"
static PagerFlags arg_pager_flags = 0; static PagerFlags arg_pager_flags = 0;
static OutputFlags arg_output_flags = 0; static OutputFlags arg_output_flags = 0;
@@ -38,32 +37,13 @@ static const char* arg_machine = NULL;
STATIC_DESTRUCTOR_REGISTER(arg_names, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_names, strv_freep);
static int help(void) { COMMAND(
_cleanup_free_ char *link = NULL; "systemd-cgls\0",
_cleanup_(table_unrefp) Table *options = NULL; "Recursively show control group contents.",
int r; .argspec = "[CGROUP…]\0" "--unit|--user-unit UNIT…\0",
.man_pages = "systemd-cgls.1\0",
r = terminal_urlify_man("systemd-cgls", "1", &link); .pager_flags = &arg_pager_flags,
if (r < 0) );
return log_oom();
r = option_parser_get_help_table(&options);
if (r < 0)
return r;
printf("%s [OPTIONS...] [CGROUP...]\n\n"
"%sRecursively show control group contents.%s\n\n",
program_invocation_short_name,
ansi_highlight(),
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[]) { static int parse_argv(int argc, char *argv[]) {
assert(argc >= 1); assert(argc >= 1);
@@ -76,7 +56,7 @@ static int parse_argv(int argc, char *argv[]) {
switch (c) { switch (c) {
OPTION_COMMON_HELP: OPTION_COMMON_HELP:
return help(); return command_print_help("systemd-cgls");
OPTION_COMMON_VERSION: OPTION_COMMON_VERSION:
return version(); return version();
@@ -153,6 +133,9 @@ static int parse_argv(int argc, char *argv[]) {
if (strv_extend(&arg_names, opts.arg) < 0) /* push arg */ if (strv_extend(&arg_names, opts.arg) < 0) /* push arg */
return log_oom(); return log_oom();
break; break;
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(SD_JSON_FORMAT_OFF);
} }
if (arg_machine && arg_show_unit != SHOW_UNIT_NONE) if (arg_machine && arg_show_unit != SHOW_UNIT_NONE)
@@ -19,6 +19,7 @@ INTROSPECTABLE=(
systemd-binfmt systemd-binfmt
systemd-bsod systemd-bsod
systemd-cat systemd-cat
systemd-cgls
systemd-dissect systemd-dissect
systemd-firstboot systemd-firstboot
systemd-hwdb systemd-hwdb