diff options
Diffstat (limited to 'src/core/show-status.c')
-rw-r--r-- | src/core/show-status.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/core/show-status.c b/src/core/show-status.c index fd9aeb9416..d8d2317d38 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -5,26 +5,30 @@ #include "io-util.h" #include "parse-util.h" #include "show-status.h" +#include "string-table.h" #include "string-util.h" #include "terminal-util.h" #include "util.h" +static const char* const show_status_table[_SHOW_STATUS_MAX] = { + [SHOW_STATUS_NO] = "no", + [SHOW_STATUS_AUTO] = "auto", + [SHOW_STATUS_TEMPORARY] = "temporary", + [SHOW_STATUS_YES] = "yes", +}; + +DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(show_status, ShowStatus, SHOW_STATUS_YES); + int parse_show_status(const char *v, ShowStatus *ret) { - int r; + ShowStatus s; - assert(v); assert(ret); - if (streq(v, "auto")) { - *ret = SHOW_STATUS_AUTO; - return 0; - } - - r = parse_boolean(v); - if (r < 0) - return r; + s = show_status_from_string(v); + if (s < 0 || s == SHOW_STATUS_TEMPORARY) + return -EINVAL; - *ret = r ? SHOW_STATUS_YES : SHOW_STATUS_NO; + *ret = s; return 0; } |