1 /* SPDX-License-Identifier: LGPL-2.1+ */
8 static bool arg_verbose
= false;
10 static void help(void) {
12 "Report whether we are connected to an external power source.\n\n"
13 " -h --help Show this help\n"
14 " --version Show package version\n"
15 " -v --verbose Show state as text\n"
16 , program_invocation_short_name
);
19 static int parse_argv(int argc
, char *argv
[]) {
25 static const struct option options
[] = {
26 { "help", no_argument
, NULL
, 'h' },
27 { "version", no_argument
, NULL
, ARG_VERSION
},
28 { "verbose", no_argument
, NULL
, 'v' },
37 while ((c
= getopt_long(argc
, argv
, "hv", options
, NULL
)) >= 0)
56 assert_not_reached("Unhandled option");
60 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
61 "%s takes no arguments.",
62 program_invocation_short_name
);
67 static int run(int argc
, char *argv
[]) {
70 /* This is mostly intended to be used for scripts which want
71 * to detect whether AC power is plugged in or not. */
73 log_parse_environment();
76 r
= parse_argv(argc
, argv
);
82 return log_error_errno(r
, "Failed to read AC status: %m");
90 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);