mirror of
https://github.com/ceph/ceph
synced 2025-04-01 23:02:17 +00:00
Some fixes to double-dash support, fix warning
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
This commit is contained in:
parent
eecf4d6175
commit
31bf064b6e
@ -161,7 +161,9 @@ int main(int argc, const char **argv)
|
||||
|
||||
std::string val;
|
||||
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
|
||||
if (ceph_argparse_witharg(args, i, &val, "-s", "--section", (char*)NULL)) {
|
||||
if (ceph_argparse_double_dash(args, i)) {
|
||||
break;
|
||||
} else if (ceph_argparse_witharg(args, i, &val, "-s", "--section", (char*)NULL)) {
|
||||
sections.push_back(val);
|
||||
} else if (ceph_argparse_flag(args, i, "-r", "--resolve_search", (char*)NULL)) {
|
||||
resolve_search = true;
|
||||
|
@ -134,7 +134,10 @@ int main(int argc, const char **argv)
|
||||
|
||||
std::string val, action;
|
||||
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
|
||||
if (ceph_argparse_witharg(args, i, &val, "--dump-journal", (char*)NULL)) {
|
||||
if (ceph_argparse_double_dash(args, i)) {
|
||||
break;
|
||||
}
|
||||
else if (ceph_argparse_witharg(args, i, &val, "--dump-journal", (char*)NULL)) {
|
||||
set_special_action(action, "dump-journal");
|
||||
rank = parse_rank("dump-journal", val);
|
||||
if (i == args.end()) {
|
||||
|
@ -254,13 +254,13 @@ static void dashes_to_underscores(const char *input, char *output)
|
||||
*o++ = '\0';
|
||||
}
|
||||
|
||||
/** Once we see a standalone double dash, '--', we stop looking for any
|
||||
* other options and flags. */
|
||||
static bool handle_double_dash(std::vector<const char*> &args,
|
||||
/** Once we see a standalone double dash, '--', we should remove it and stop
|
||||
* looking for any other options and flags. */
|
||||
bool ceph_argparse_double_dash(std::vector<const char*> &args,
|
||||
std::vector<const char*>::iterator &i)
|
||||
{
|
||||
if (*i == "--") {
|
||||
i = args.end();
|
||||
if (strcmp(*i, "--") == 0) {
|
||||
i = args.erase(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -276,8 +276,6 @@ bool ceph_argparse_flag(std::vector<const char*> &args,
|
||||
const char *a;
|
||||
va_list ap;
|
||||
|
||||
if (handle_double_dash(args, i))
|
||||
return false;
|
||||
va_start(ap, i);
|
||||
while (1) {
|
||||
a = va_arg(ap, char*);
|
||||
@ -304,8 +302,6 @@ bool ceph_argparse_binary_flag(std::vector<const char*> &args,
|
||||
va_list ap;
|
||||
int strlen_a;
|
||||
|
||||
if (handle_double_dash(args, i))
|
||||
return false;
|
||||
// does this argument match any of the possibilities?
|
||||
va_start(ap, oss);
|
||||
while (1) {
|
||||
@ -354,8 +350,6 @@ bool ceph_argparse_witharg(std::vector<const char*> &args,
|
||||
va_list ap;
|
||||
int strlen_a;
|
||||
|
||||
if (handle_double_dash(args, i))
|
||||
return false;
|
||||
// does this argument match any of the possibilities?
|
||||
va_start(ap, ret);
|
||||
while (1) {
|
||||
|
@ -92,6 +92,8 @@ extern void vec_to_argv(std::vector<const char*>& args,
|
||||
int& argc, const char **&argv);
|
||||
|
||||
extern bool parse_ip_port_vec(const char *s, std::vector<entity_addr_t>& vec);
|
||||
bool ceph_argparse_double_dash(std::vector<const char*> &args,
|
||||
std::vector<const char*>::iterator &i);
|
||||
bool ceph_argparse_flag(std::vector<const char*> &args,
|
||||
std::vector<const char*>::iterator &i, ...);
|
||||
bool ceph_argparse_witharg(std::vector<const char*> &args,
|
||||
|
@ -599,7 +599,10 @@ parse_argv(std::vector<const char*>& args)
|
||||
// observer notifications later.
|
||||
std::string val;
|
||||
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
|
||||
if (ceph_argparse_flag(args, i, "--show_conf", (char*)NULL)) {
|
||||
if (ceph_argparse_double_dash(args, i)) {
|
||||
break;
|
||||
}
|
||||
else if (ceph_argparse_flag(args, i, "--show_conf", (char*)NULL)) {
|
||||
cerr << cf << std::endl;
|
||||
_exit(0);
|
||||
}
|
||||
|
@ -502,7 +502,9 @@ bool MDSMonitor::preprocess_command(MMonCommand *m)
|
||||
string val;
|
||||
epoch_t epoch = 0;
|
||||
for (std::vector<const char*>::iterator i = args.begin()+1; i != args.end(); ) {
|
||||
if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL))
|
||||
if (ceph_argparse_double_dash(args, i))
|
||||
break;
|
||||
else if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL))
|
||||
format = val;
|
||||
else if (!epoch)
|
||||
epoch = atoi(*i++);
|
||||
|
@ -141,7 +141,9 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
|
||||
epoch_t epoch = 0;
|
||||
string cmd = args[0];
|
||||
for (std::vector<const char*>::iterator i = args.begin()+1; i != args.end(); ) {
|
||||
if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL))
|
||||
if (ceph_argparse_double_dash(args, i))
|
||||
break;
|
||||
else if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL))
|
||||
format = val;
|
||||
else if (!epoch)
|
||||
epoch = atoi(*i++);
|
||||
|
@ -1179,7 +1179,9 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
|
||||
epoch_t epoch = 0;
|
||||
string cmd = args[0];
|
||||
for (std::vector<const char*>::iterator i = args.begin()+1; i != args.end(); ) {
|
||||
if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL))
|
||||
if (ceph_argparse_double_dash(args, i))
|
||||
break;
|
||||
else if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL))
|
||||
format = val;
|
||||
else if (!epoch)
|
||||
epoch = atoi(*i++);
|
||||
|
@ -782,7 +782,9 @@ bool PGMonitor::preprocess_command(MMonCommand *m)
|
||||
string what = "all";
|
||||
string val;
|
||||
for (std::vector<const char*>::iterator i = args.begin()+1; i != args.end(); ) {
|
||||
if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL)) {
|
||||
if (ceph_argparse_double_dash(args, i)) {
|
||||
break;
|
||||
} else if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL)) {
|
||||
format = val;
|
||||
} else {
|
||||
what = *i++;
|
||||
|
@ -1175,7 +1175,9 @@ int main(int argc, const char **argv)
|
||||
std::vector<const char*>::iterator i;
|
||||
std::string val;
|
||||
for (i = args.begin(); i != args.end(); ) {
|
||||
if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
|
||||
if (ceph_argparse_double_dash(args, i)) {
|
||||
break;
|
||||
} else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
|
||||
usage(cout);
|
||||
exit(0);
|
||||
} else if (ceph_argparse_flag(args, i, "-f", "--force", (char*)NULL)) {
|
||||
|
@ -116,7 +116,10 @@ TEST(CephArgParse, DoubleDash) {
|
||||
i != args.arr.end(); )
|
||||
{
|
||||
std::string myarg;
|
||||
if (ceph_argparse_witharg(args.arr, i, &myarg, "--foo", (char*)NULL)) {
|
||||
if (ceph_argparse_double_dash(args.arr, i)) {
|
||||
break;
|
||||
}
|
||||
else if (ceph_argparse_witharg(args.arr, i, &myarg, "--foo", (char*)NULL)) {
|
||||
foo = atoi(myarg.c_str());
|
||||
}
|
||||
else if (ceph_argparse_witharg(args.arr, i, &myarg, "--bar", (char*)NULL)) {
|
||||
|
@ -135,7 +135,6 @@ TEST(DaemonConfig, InjectArgsBooleans) {
|
||||
int ret;
|
||||
char buf[128];
|
||||
char *tmp = buf;
|
||||
char buf2[128];
|
||||
|
||||
// Change log_to_syslog
|
||||
std::ostringstream chat;
|
||||
|
@ -51,8 +51,9 @@ int main(int argc, const char **argv)
|
||||
string oid("test_object");
|
||||
string pool_name("test_pool");
|
||||
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
|
||||
if (strcmp(*i, "--") == 0)
|
||||
if (ceph_argparse_double_dash(args, i)) {
|
||||
break;
|
||||
}
|
||||
else if (ceph_argparse_witharg(args, i, &val, "--oid", "-o", (char*)NULL)) {
|
||||
oid = val;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user