File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5050.cache
5151.pytest_cache
5252
53- .devcontainer
53+ .devcontainer
54+
55+ settings.json5
Original file line number Diff line number Diff line change 1919#include <rsl/cli/annotations.hpp>
2020#include <rsl/cli/spec.hpp>
2121
22+ #include <rsl/json5/json5.hpp>
23+
2224namespace rsl {
2325
2426class ProgramInfo {
@@ -78,18 +80,19 @@ T load_config(std::vector<std::string_view> args_in) {
7880
7981 _impl::ArgumentTuple<T> args_tuple;
8082
81- auto config = T::config_path();
82- std::println(" config: {}", config );
83+ auto config = json5::load( T::config_path() );
84+ config.template update_argtuple<T>(args_tuple );
8385
86+
8487 for (auto argument : parsed_args) {
8588 argument(&args_tuple);
8689 }
8790
88- for (auto arg : spec.arguments | std::views::drop(parsed_args.size())) {
89- if (!arg.is_optional) {
90- parser.fail("Missing required argument `{}`", arg.name);
91- }
92- }
91+ // for (auto arg : spec.arguments | std::views::drop(parsed_args.size())) {
92+ // if (!arg.is_optional) {
93+ // parser.fail("Missing required argument `{}`", arg.name);
94+ // }
95+ // }
9396
9497 T object = _impl::default_construct<T>(args_tuple);
9598
Original file line number Diff line number Diff line change 44#include < vector>
55#include < charconv>
66
7+ #include < rsl/constexpr_assert>
78#include < rsl/_impl/default_construct.hpp>
89
910namespace rsl ::json5 {
@@ -37,14 +38,16 @@ struct Value {
3738 template <typename T>
3839 void update_argtuple (_impl::ArgumentTuple<T>& args) const {
3940 Object obj = as_object ();
40-
41+ constexpr_assert (obj. size () != 0 );
4142 constexpr auto ctx = std::meta::access_context::current ();
4243 constexpr auto members = std::define_static_array (nonstatic_data_members_of (dealias (^^T), ctx));
44+ constexpr auto base_count = bases_of (dealias (^^T), ctx).size ();
4345 template for (constexpr auto Idx : std::views::iota (0zu, members.size ())) {
4446 constexpr auto name = std::define_static_string (identifier_of (members[Idx]));
4547 auto it = obj.find (name);
4648 if (it != obj.end ()) {
47- get<Idx>(args) = it->second .template as <typename [:type_of (members[Idx]):]>();
49+ using target_type = [:type_of (members[Idx]):];
50+ get<base_count + Idx>(args) = it->second .template as <target_type>();
4851 }
4952 }
5053 }
@@ -92,4 +95,6 @@ struct Parser {
9295 void expect_more () const ;
9396};
9497
98+ Value load (std::string_view path);
99+
95100} // namespace rsl::json5
Original file line number Diff line number Diff line change 1+ #include < filesystem>
12#include < algorithm>
3+ #include < fstream>
4+ #include < sstream>
25#include < stdexcept>
36#include < format>
4- #include < print>
57
68#include < rsl/json5/json5.hpp>
79
@@ -171,4 +173,16 @@ std::string Value::as_string() const {
171173 return content;
172174}
173175
176+ Value load (std::string_view path) {
177+ auto config_path = std::filesystem::path (path);
178+ if (!exists (config_path)) {
179+ throw std::runtime_error (std::format (" File {} does not exist." , path));
180+ }
181+ auto in = std::ifstream (config_path);
182+ std::stringstream buffer;
183+ buffer << in.rdbuf ();
184+
185+ return Value (buffer.str ());
186+ }
187+
174188} // namespace rsl::json5
You can’t perform that action at this time.
0 commit comments