/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include <getopt.h>
#include <linux/vt.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include "build.h"
#include "fd-util.h"
#include "fileio.h"
+#include "format-table.h"
#include "io-util.h"
#include "log.h"
#include "logs-show.h"
#include "main-func.h"
+#include "options.h"
#include "parse-argument.h"
#include "pretty-print.h"
#include "qrcode-util.h"
static int help(void) {
_cleanup_free_ char *link = NULL;
+ _cleanup_(table_unrefp) Table *options = NULL;
int r;
r = terminal_urlify_man("systemd-bsod", "8", &link);
if (r < 0)
return log_oom();
- printf("%1$s [OPTIONS...]\n\n"
- "%5$sFilter the journal to fetch the first message from the current boot with an%6$s\n"
- "%5$semergency log level and display it as a string and a QR code.%6$s\n"
- "\n%3$sOptions:%4$s\n"
- " -h --help Show this help\n"
- " --version Show package version\n"
- " -c --continuous Make systemd-bsod wait continuously\n"
- " for changes in the journal\n"
- " --tty=TTY Specify path to TTY to use\n"
- "\nSee the %2$s for details.\n",
+ r = option_parser_get_help_table(&options);
+ if (r < 0)
+ return r;
+
+ printf("%s [OPTIONS...]\n\n"
+ "%sFilter the journal to fetch the first message from the current boot with an\n"
+ "emergency log level and display it as a string and a QR code.%s\n"
+ "\n%sOptions:%s\n",
program_invocation_short_name,
- link,
- ansi_underline(),
- ansi_normal(),
ansi_highlight(),
+ ansi_normal(),
+ ansi_underline(),
ansi_normal());
+ r = table_print_or_warn(options);
+ if (r < 0)
+ return r;
+
+ printf("\nSee the %s for details.\n", link);
return 0;
}
return r;
}
-static int parse_argv(int argc, char * argv[]) {
-
- enum {
- ARG_VERSION = 0x100,
- ARG_TTY,
- };
-
- static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "version", no_argument, NULL, ARG_VERSION },
- { "continuous", no_argument, NULL, 'c' },
- { "tty", required_argument, NULL, ARG_TTY },
- {}
- };
-
- int c, r;
-
+static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hc", options, NULL)) >= 0)
+ OptionParser state = { argc, argv };
+ const char *arg;
+ int r;
+ FOREACH_OPTION(&state, c, &arg, /* on_error= */ return c)
switch (c) {
- case 'h':
+ OPTION_COMMON_HELP:
return help();
- case ARG_VERSION:
+ OPTION_COMMON_VERSION:
return version();
- case 'c':
+ OPTION('c', "continuous", NULL, "Continuously wait for changes in the journal"):
arg_continuous = true;
break;
- case ARG_TTY:
- r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_tty);
+ OPTION_LONG("tty", "TTY", "Specify path to TTY to use"):
+ r = parse_path_argument(arg, /* suppress_root= */ false, &arg_tty);
if (r < 0)
return r;
-
break;
-
- case '?':
- return -EINVAL;
-
- default:
- assert_not_reached();
}
- if (optind < argc)
+ if (option_parser_get_n_args(&state) > 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"%s takes no argument.",
program_invocation_short_name);