1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 static bool arg_verbose
= false;
9 static void help(void) {
11 "Report whether we are connected to an external power source.\n\n"
12 " -h --help Show this help\n"
13 " --version Show package version\n"
14 " -v --verbose Show state as text\n"
15 , program_invocation_short_name
);
18 static int parse_argv(int argc
, char *argv
[]) {
24 static const struct option options
[] = {
25 { "help", no_argument
, NULL
, 'h' },
26 { "version", no_argument
, NULL
, ARG_VERSION
},
27 { "verbose", no_argument
, NULL
, 'v' },
36 while ((c
= getopt_long(argc
, argv
, "hv", options
, NULL
)) >= 0)
55 assert_not_reached("Unhandled option");
59 log_error("%s takes no arguments.", program_invocation_short_name
);
66 static int run(int argc
, char *argv
[]) {
69 /* This is mostly intended to be used for scripts which want
70 * to detect whether AC power is plugged in or not. */
72 log_parse_environment();
75 r
= parse_argv(argc
, argv
);
81 return log_error_errno(r
, "Failed to read AC status: %m");
89 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);