From: Yehuda Sadeh Date: Tue, 3 Dec 2019 21:58:49 +0000 (-0800) Subject: ceph_argparse: binary flag value can be separate arg X-Git-Tag: v15.1.0~22^2~24 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=82e44d9c8ca91f2f7d5f1cb1d1fe54a766351fcf;p=ceph.git ceph_argparse: binary flag value can be separate arg Resurrect old behavior where a binary flag could be detached from the argument, e.g., "--rgw-cache-enabled false". Signed-off-by: Yehuda Sadeh --- diff --git a/src/common/ceph_argparse.cc b/src/common/ceph_argparse.cc index 662ed296a1e0..cdb41846e7e6 100644 --- a/src/common/ceph_argparse.cc +++ b/src/common/ceph_argparse.cc @@ -309,6 +309,18 @@ bool ceph_argparse_flag(std::vector &args, } } +static bool check_bool_str(const char *val, int *ret) +{ + if ((strcmp(val, "true") == 0) || (strcmp(val, "1") == 0)) { + *ret = 1; + return true; + } else if ((strcmp(val, "false") == 0) || (strcmp(val, "0") == 0)) { + *ret = 0; + return true; + } + return false; +} + static bool va_ceph_argparse_binary_flag(std::vector &args, std::vector::iterator &i, int *ret, std::ostream *oss, va_list ap) @@ -330,12 +342,7 @@ static bool va_ceph_argparse_binary_flag(std::vector &args, if (first[strlen_a] == '=') { i = args.erase(i); const char *val = first + strlen_a + 1; - if ((strcmp(val, "true") == 0) || (strcmp(val, "1") == 0)) { - *ret = 1; - return true; - } - else if ((strcmp(val, "false") == 0) || (strcmp(val, "0") == 0)) { - *ret = 0; + if (check_bool_str(val, ret)) { return true; } if (oss) { @@ -346,8 +353,18 @@ static bool va_ceph_argparse_binary_flag(std::vector &args, return true; } else if (first[strlen_a] == '\0') { - i = args.erase(i); - *ret = 1; + auto next = i+1; + if (next != args.end() && + *next && + (*next)[0] != '-') { + if (check_bool_str(*next, ret)) { + i = args.erase(i); + i = args.erase(i); + return true; + } + } + i = args.erase(i); + *ret = 1; return true; } }