diff options
| author | Craig Barnes <craigbarnes@protonmail.com> | 2021-02-11 11:08:18 +0000 |
|---|---|---|
| committer | Craig Barnes <craigbarnes@protonmail.com> | 2021-02-11 11:08:18 +0000 |
| commit | 5437321f97e21a3fc6fca79fbdf05ca8d6199b35 (patch) | |
| tree | c4be83c79d81e37086ed6ab40bed7fd0d72fb44f /client.c | |
| parent | changelog: -d,--log-level (diff) | |
main: client: factor out some common code for "--log-level" option
Diffstat (limited to 'client.c')
| -rw-r--r-- | client.c | 37 |
1 files changed, 8 insertions, 29 deletions
@@ -17,6 +17,7 @@ #include "client-protocol.h" #include "debug.h" #include "foot-features.h" +#include "macros.h" #include "util.h" #include "version.h" #include "xmalloc.h" @@ -156,38 +157,16 @@ main(int argc, char *const *argv) break; case 'd': { - static const char *log_level_map[] = { -#if defined(_DEBUG) - [LOG_CLASS_DEBUG] = "debug", -#endif - [LOG_CLASS_INFO] = "info", - [LOG_CLASS_WARNING] = "warning", - [LOG_CLASS_ERROR] = "error", - }; - - bool valid_log_level = false; - for (size_t i = 0; i < ALEN(log_level_map); i++) { - if (strcmp(optarg, log_level_map[i]) == 0) { - log_level = i; - valid_log_level = true; - break; - } - } - - if (!valid_log_level) { + int lvl = log_level_from_string(optarg); + if (unlikely(lvl < 0)) { fprintf( - stderr, "-d,--log-level: %s: argument must be one of ", - optarg); - - for (size_t i = 0; i < ALEN(log_level_map); i++) { - fprintf(stderr, "'%s'%s", - log_level_map[i], - i < ALEN(log_level_map) - 1 ? " , " : ""); - } - fprintf(stderr, "\n"); - + stderr, + "-d,--log-level: %s: argument must be one of %s\n", + optarg, + log_level_string_hint()); return EXIT_FAILURE; } + log_level = lvl; break; } |
