From 55c5cfab46c27586050e5b417b7b5ec9a748ac39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 9 May 2019 19:14:58 +0200 Subject: [PATCH] main: add -c,--check-config When this option is used, we exit after loading the configuration. Either with an error message and a non-zero exit code (bad config), or no messages and a zero exit code (good config). --- doc/f00bar.1.scd | 5 +++++ main.c | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/f00bar.1.scd b/doc/f00bar.1.scd index 6116021..d8f8751 100644 --- a/doc/f00bar.1.scd +++ b/doc/f00bar.1.scd @@ -8,6 +8,11 @@ f00bar - modular status panel for X11 and Wayland # OPTIONS +*-c, --check-config* + Verify the configuration and then quit. If no errors are detected, + nothing is printed and the exit code is 0. If there are errors, + these are printed on stdout and the exit code is non-zero. + *-v, --version* Show the version number and quit diff --git a/main.c b/main.c index 50d9804..d7a3c83 100644 --- a/main.c +++ b/main.c @@ -124,7 +124,8 @@ print_usage(const char *prog_name) printf("Usage: %s [OPTION]...\n", prog_name); printf("\n"); printf("Options:\n"); - printf(" -v,--version print f00sel version and quit\n"); + printf(" -c,--check-config verify configuration then quit\n" + " -v,--version print f00sel version and quit\n"); } int @@ -133,17 +134,24 @@ main(int argc, char *const *argv) setlocale(LC_ALL, ""); static const struct option longopts[] = { + {"check-config", no_argument, 0, 'c'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {NULL, no_argument, 0, 0}, }; + bool verify_config = false; + while (true) { - int c = getopt_long(argc, argv, ":vh", longopts, NULL); + int c = getopt_long(argc, argv, ":cvh", longopts, NULL); if (c == -1) break; switch (c) { + case 'c': + verify_config = true; + break; + case 'v': printf("f00bar version %s\n", F00BAR_VERSION); return EXIT_SUCCESS; @@ -194,6 +202,12 @@ main(int argc, char *const *argv) return 1; } + if (verify_config) { + bar->destroy(bar); + close(abort_fd); + return 0; + } + bar->abort_fd = abort_fd; thrd_t bar_thread;