mirror of https://github.com/jarro2783/cxxopts.git
C++17 std::filesystem::path support added
This commit is contained in:
parent
f029892dab
commit
a1976187bc
|
|
@ -73,6 +73,12 @@ THE SOFTWARE.
|
|||
# define CXXOPTS_HAS_OPTIONAL
|
||||
# endif
|
||||
# endif
|
||||
# if __has_include(<filesystem>)
|
||||
# include <filesystem>
|
||||
# ifdef __cpp_lib_filesystem
|
||||
# define CXXOPTS_HAS_FILESYSTEM
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define CXXOPTS_FALLTHROUGH
|
||||
|
|
@ -1074,6 +1080,15 @@ parse_value(const std::string& text, std::optional<T>& value)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CXXOPTS_HAS_FILESYSTEM
|
||||
inline
|
||||
void
|
||||
parse_value(const std::string& text, std::filesystem::path& value)
|
||||
{
|
||||
value.assign(text);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline
|
||||
void parse_value(const std::string& text, char& c)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -732,6 +732,27 @@ TEST_CASE("std::optional", "[optional]") {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CXXOPTS_HAS_FILESYSTEM
|
||||
TEST_CASE("std::filesystem::path", "[path]") {
|
||||
std::filesystem::path path;
|
||||
cxxopts::Options options("path", " - tests path");
|
||||
options.add_options()
|
||||
("path", "a path", cxxopts::value<std::filesystem::path>(path));
|
||||
|
||||
Argv av({"path", "--path", "Hello World.txt"});
|
||||
|
||||
auto** argv = av.argv();
|
||||
auto argc = av.argc();
|
||||
|
||||
REQUIRE(path.empty());
|
||||
|
||||
options.parse(argc, argv);
|
||||
|
||||
REQUIRE(!path.empty());
|
||||
CHECK(path == "Hello World.txt");
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Unrecognised options", "[options]") {
|
||||
cxxopts::Options options("unknown_options", " - test unknown options");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue