// @requires-reflection #include #include #include #include #include namespace arg = Void::Argparse; namespace { struct Opts { [[= arg::Short{ 'v'}]][[= arg::Help{"verbose output"}]] bool verbose = false; [[= arg::Help{"output path"}]] std::string out = "a.out"; std::optional config; [[= arg::Positional{}]] std::string input = ""; }; } // namespace // @tag reflection Void::Testing::Test argparse_reflective_parse() { const char* argv[] = {"prog", "-v", "--out=x.bin", "foo.txt"}; const auto o = arg::parse(4, argv, "prog"); Void::Testing::expect(o.has_value()); Void::Testing::expect_eq(o->verbose, true); Void::Testing::expect_eq(o->out, std::string{"x.bin"}); Void::Testing::expect_eq(o->input, std::string{"foo.txt"}); Void::Testing::expect(!o->config.has_value()); } // @tag reflection Void::Testing::Test argparse_reflective_defaults() { const char* argv[] = {"prog", "bar.txt"}; const auto o = arg::parse(2, argv, "prog"); Void::Testing::expect(o.has_value()); Void::Testing::expect_eq(o->verbose, false); // flag default Void::Testing::expect_eq(o->out, std::string{"a.out"}); // option default Void::Testing::expect_eq(o->input, std::string{"bar.txt"}); }