163 vpJsonArgumentParser(
const std::string &description,
const std::string &jsonFileArgumentName,
const std::string &nestSeparator);
192 const auto getter = [name,
this](nlohmann::json &j,
bool create) -> nlohmann::json * {
194 nlohmann::json *f = &j;
196 std::string name_copy = name;
198 while ((pos = name_copy.find(m_nestSeparator)) != std::string::npos) {
199 token = name_copy.substr(0, pos);
201 name_copy.erase(0, pos + m_nestSeparator.length());
202 if (create && !f->contains(token)) {
205 else if (!f->contains(token)) {
210 if (create && !f->contains(name_copy)) {
211 (*f)[name_copy] = {};
213 else if (!f->contains(name_copy)) {
216 f = &(f->at(name_copy));
220 m_parsers[name] = [¶meter, required, getter, name](nlohmann::json &j) {
221 const nlohmann::json *field = getter(j,
false);
222 const bool fieldHasNoValue = field ==
nullptr || (field !=
nullptr && field->is_null());
223 if (required && fieldHasNoValue) {
224 std::stringstream ss;
225 ss <<
"Argument " << name <<
" is required, but no value was provided" << std::endl;
228 else if (!fieldHasNoValue) {
229 field->get_to(parameter);
233 m_updaters[name] = [getter](nlohmann::json &j,
const std::string &s) {
234 nlohmann::json *field = getter(j,
true);
235 *field = convertCommandLineArgument<T>(s);
238 m_helpers[name] = [
help, parameter, required]() -> std::string {
239 std::stringstream ss;
240 nlohmann::json repr = parameter;
241 ss <<
help << std::endl <<
"Default: " << repr;
243 ss << std::endl <<
"Required";
246 ss << std::endl <<
"Optional";
251 nlohmann::json *exampleField = getter(m_exampleJson,
true);
252 *exampleField = parameter;
282 std::map<std::string, std::function<void(nlohmann::json &,
const std::string &)>> m_updaters;