Skip to content

Commit

Permalink
Fix bug with spaces in args
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Nov 30, 2019
1 parent 4f23640 commit 2afcc7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ struct value_parser
}
};

template<>
struct value_parser<std::string>
{
static std::string apply(const std::string& x)
{
return x;
}
};

template<class T, typename std::enable_if<(not is_container<T>{} or std::is_convertible<T, std::string>{}), int>::type = 0>
void write_value_to(T& result, const std::string& x)
{
Expand Down
8 changes: 8 additions & 0 deletions test/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ PROVE_CASE()
PROVE_CHECK(cmd.name == "hello");
}

PROVE_CASE()
{
single_value_cmd cmd;
args::parse(cmd, {"-N", "Nobody, or am I?", "-C", "4"});
PROVE_CHECK(cmd.count == 4);
PROVE_CHECK(cmd.name == "Nobody, or am I?");
}

struct multi_value_cmd
{
int count;
Expand Down

0 comments on commit 2afcc7f

Please sign in to comment.