[PATCH 3/9] cli: refactor boolean argument processing

Jani Nikula jani at nikula.org
Tue Sep 19 13:39:23 PDT 2017


Clean up the control flow to prepare for future changes. No functional
changes.
---
 command-line-arguments.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/command-line-arguments.c b/command-line-arguments.c
index dc517b06ff60..7fd58165278f 100644
--- a/command-line-arguments.c
+++ b/command-line-arguments.c
@@ -41,21 +41,20 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
 
 static notmuch_bool_t
 _process_boolean_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {
-
-    if (next == '\0') {
-	*((notmuch_bool_t *)arg_desc->output_var) = TRUE;
-	return TRUE;
-    }
-    if (strcmp (arg_str, "false") == 0) {
-	*((notmuch_bool_t *)arg_desc->output_var) = FALSE;
-	return TRUE;
-    }
-    if (strcmp (arg_str, "true") == 0) {
-	*((notmuch_bool_t *)arg_desc->output_var) = TRUE;
-	return TRUE;
+    notmuch_bool_t value;
+
+    if (next == '\0' || strcmp (arg_str, "true") == 0) {
+	value = TRUE;
+    } else if (strcmp (arg_str, "false") == 0) {
+	value = FALSE;
+    } else {
+	fprintf (stderr, "Unknown argument \"%s\" for (boolean) option \"%s\".\n", arg_str, arg_desc->name);
+	return FALSE;
     }
-    fprintf (stderr, "Unknown argument \"%s\" for (boolean) option \"%s\".\n", arg_str, arg_desc->name);
-    return FALSE;
+
+    *((notmuch_bool_t *)arg_desc->output_var) = value;
+
+    return TRUE;
 }
 
 static notmuch_bool_t
-- 
2.11.0



More information about the notmuch mailing list