Skip to content

Commit

Permalink
Merge remote-tracking branch 'gh/next'
Browse files Browse the repository at this point in the history
  • Loading branch information
liewegas committed May 31, 2015
2 parents 5652518 + f5a9580 commit c8705e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/common/ceph_argparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void vec_to_argv(const char *argv0, std::vector<const char*>& args,
void ceph_arg_value_type(const char * nextargstr, bool *bool_option, bool *bool_numeric)
{
bool is_numeric = true;
bool is_float = false;
bool is_option;

if (nextargstr == NULL) {
Expand All @@ -173,6 +174,11 @@ void ceph_arg_value_type(const char * nextargstr, bool *bool_option, bool *bool_
if (nextargstr[0] == '-')
continue;
}
if ( (nextargstr[i] == '.') && (is_float == false) ) {
is_float = true;
continue;
}

is_numeric = false;
break;
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/ceph_argparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,30 @@ TEST(CephArgParse, WithDashesAndUnderscores) {
ASSERT_EQ(found_baz, "");
}

TEST(CephArgParse, WithFloat) {
const char *BAZSTUFF1[] = { "./myprog", "--foo", "50.5", "--bar", "52", NULL };

VectorContainer bazstuff1(BAZSTUFF1);
ostringstream err;
float foo;
int bar = -1;
for (std::vector<const char*>::iterator i = bazstuff1.arr.begin();
i != bazstuff1.arr.end(); )
{
if (ceph_argparse_double_dash(bazstuff1.arr, i)) {
break;
} else if (ceph_argparse_witharg(bazstuff1.arr, i, &foo, err, "--foo", (char*)NULL)) {
ASSERT_EQ(string(""), err.str());
} else if (ceph_argparse_witharg(bazstuff1.arr, i, &bar, err, "--bar", (char*)NULL)) {
ASSERT_EQ(string(""), err.str());
}
else {
++i;
}
}
ASSERT_EQ(foo, 50.5);
ASSERT_EQ(bar, 52);
}

TEST(CephArgParse, WithInt) {
const char *BAZSTUFF1[] = { "./myprog", "--foo", "50", "--bar", "52", NULL };
Expand Down

0 comments on commit c8705e5

Please sign in to comment.