diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index b2eb41d5ef..3027c90e47 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -16,6 +16,7 @@ #include "sd-daemon.h" #include "sd-event.h" #include "sd-id128.h" +#include "sd-json.h" #include "sd-netlink.h" #include "sd-path.h" #include "sd-varlink.h" @@ -54,7 +55,6 @@ #include "fdset.h" #include "fileio.h" #include "fork-notify.h" -#include "format-table.h" #include "format-util.h" #include "fs-util.h" #include "gpt.h" @@ -93,7 +93,6 @@ #include "nspawn-setuid.h" #include "nspawn-stub-pid1.h" #include "nsresource.h" -#include "options.h" #include "os-util.h" #include "osc-context.h" #include "pager.h" @@ -135,6 +134,7 @@ #include "unit-name.h" #include "user-record.h" #include "user-util.h" +#include "verbs.h" #include "vpick.h" /* The notify socket inside the container it can use to talk to nspawn using the sd_notify(3) protocol */ @@ -318,6 +318,14 @@ STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep); STATIC_DESTRUCTOR_REGISTER(arg_background, freep); STATIC_DESTRUCTOR_REGISTER(arg_forward_journal, freep); +COMMAND( + "systemd-nspawn\0", + "Spawn a command or OS in a lightweight container.", + .argspec = "[PATH] [ARGUMENTS…]\0", + .man_pages = "systemd-nspawn.1\0", + .pager_flags = &arg_pager_flags, +); + static int parse_private_users( const char *s, UserNamespaceMode *ret_userns_mode, @@ -383,69 +391,6 @@ static int parse_private_users( return 0; } -static int help(void) { - _cleanup_free_ char *link = NULL; - int r; - - pager_open(arg_pager_flags); - - r = terminal_urlify_man("systemd-nspawn", "1", &link); - if (r < 0) - return log_oom(); - - static const char* const groups[] = { - NULL, - "Image", - "Execution", - "System Identity", - "Properties", - "User Namespacing", - "Networking", - "Security", - "Resources", - "Integration", - "Mounts", - "Input/Output", - "Credentials", - "Other", - }; - - Table* tables[ELEMENTSOF(groups)] = {}; - CLEANUP_ELEMENTS(tables, table_unref_array_clear); - - for (size_t i = 0; i < ELEMENTSOF(groups); i++) { - r = option_parser_get_help_table_group(groups[i], &tables[i]); - if (r < 0) - return r; - } - - (void) table_sync_column_widths(0, tables[0], tables[1], tables[2], tables[3], - tables[4], tables[5], tables[6], tables[7], - tables[8], tables[9], tables[10], tables[11], - tables[12], tables[13]); - - printf("%s [OPTIONS...] [PATH] [ARGUMENTS...]\n\n" - "%sSpawn a command or OS in a lightweight container.%s\n\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal()); - - r = table_print_or_warn(tables[0]); - if (r < 0) - return r; - - for (size_t i = 1; i < ELEMENTSOF(groups); i++) { - printf("\n%s%s:%s\n", ansi_underline(), groups[i], ansi_normal()); - - r = table_print_or_warn(tables[i]); - if (r < 0) - return r; - } - - printf("\nSee the %s for details.\n", link); - return 0; -} - static int custom_mount_check_all(void) { FOREACH_ARRAY(m, arg_custom_mounts, arg_n_custom_mounts) if (path_equal(m->destination, "/") && arg_userns_mode != USER_NAMESPACE_NO) { @@ -614,7 +559,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help("systemd-nspawn"); OPTION_COMMON_VERSION: return version(); @@ -1445,6 +1390,9 @@ static int parse_argv(int argc, char *argv[]) { OPTION_LONG("system", NULL, "Run in the system service manager scope"): arg_runtime_scope = RUNTIME_SCOPE_SYSTEM; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } } diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index e1b5d023c3..6dd49b596e 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -66,6 +66,7 @@ INTROSPECTABLE=( systemd-network-generator systemd-networkd-wait-online systemd-notify + systemd-nspawn systemd-oomd systemd-path systemd-pcrextend