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).
This commit is contained in:
Daniel Eklöf 2019-05-09 19:14:58 +02:00
parent cb0bc20b38
commit 55c5cfab46
2 changed files with 21 additions and 2 deletions

View file

@ -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

18
main.c
View file

@ -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;