]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/service-util.c
uefi: emphasize a bit that EV_IPL event logs is the past, EV_EVENT_TAG the future
[thirdparty/systemd.git] / src / shared / service-util.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <getopt.h>
4 #include <stdio.h>
5
6 #include "alloc-util.h"
7 #include "build.h"
8 #include "pretty-print.h"
9 #include "service-util.h"
10 #include "terminal-util.h"
11
12 static int help(const char *program_path, const char *service, const char *description, bool bus_introspect) {
13 _cleanup_free_ char *link = NULL;
14 int r;
15
16 r = terminal_urlify_man(service, "8", &link);
17 if (r < 0)
18 return log_oom();
19
20 printf("%1$s [OPTIONS...]\n"
21 "\n%5$s%7$s%6$s\n"
22 "\nThis program takes no positional arguments.\n"
23 "\n%3$sOptions:%4$s\n"
24 " -h --help Show this help\n"
25 " --version Show package version\n"
26 "%8$s"
27 "\nSee the %2$s for details.\n",
28 program_path,
29 link,
30 ansi_underline(),
31 ansi_normal(),
32 ansi_highlight(),
33 ansi_normal(),
34 description,
35 bus_introspect ? " --bus-introspect=PATH Write D-Bus XML introspection data\n" : "");
36
37 return 0; /* No further action */
38 }
39
40 int service_parse_argv(
41 const char *service,
42 const char *description,
43 const BusObjectImplementation* const* bus_objects,
44 int argc, char *argv[]) {
45
46 enum {
47 ARG_VERSION = 0x100,
48 ARG_BUS_INTROSPECT,
49 };
50
51 static const struct option options[] = {
52 { "help", no_argument, NULL, 'h' },
53 { "version", no_argument, NULL, ARG_VERSION },
54 { "bus-introspect", required_argument, NULL, ARG_BUS_INTROSPECT },
55 {}
56 };
57
58 int c;
59
60 assert(argc >= 0);
61 assert(argv);
62
63 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
64 switch (c) {
65
66 case 'h':
67 return help(argv[0], service, description, bus_objects);
68
69 case ARG_VERSION:
70 return version();
71
72 case ARG_BUS_INTROSPECT:
73 return bus_introspect_implementations(
74 stdout,
75 optarg,
76 bus_objects);
77
78 case '?':
79 return -EINVAL;
80
81 default:
82 assert_not_reached();
83 }
84
85 if (optind < argc)
86 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
87 "This program takes no arguments.");
88
89 return 1; /* Further action */
90 }