8 jsonParser
const &_self(jsonParser
const &_input, fs::path _path) {
12 auto it = _input.find_at(_path);
13 if (it == _input.end()) {
24 self(_self(_input, _path)),
28 error.insert(std::string(
"Error: ") +
"Required property '" +
29 _path.string() +
"' not found.");
57 auto lambda = [](
const PairType &pair) {
return pair.second->valid(); };
62 std::map<fs::path, std::set<std::string>> result;
66 for (
const auto &val : *
this) {
67 const auto &parser = *val.second;
68 auto all_subparser_warnings = parser.all_warnings();
69 if (all_subparser_warnings.size()) {
70 result.insert(all_subparser_warnings.begin(),
71 all_subparser_warnings.end());
78 std::map<fs::path, std::set<std::string>> result;
79 if (this->
error.size()) {
82 for (
const auto &val : *
this) {
83 const auto &parser = *val.second;
84 auto all_subparser_errors = parser.all_errors();
85 if (all_subparser_errors.size()) {
86 result.insert(all_subparser_errors.begin(), all_subparser_errors.end());
93 const std::shared_ptr<KwargsParser> &subparser) {
99 std::make_shared<KwargsParser>(this->
input, this->
relpath(option),
false);
100 subparser->error.insert(message);
101 insert(subparser->path, subparser);
106 std::make_shared<KwargsParser>(this->
input, this->
relpath(option),
false);
107 subparser->warning.insert(message);
108 insert(subparser->path, subparser);
112 bool all_necessary =
true;
113 for (
auto opt_it =
self.
begin(); opt_it !=
self.end(); ++opt_it) {
114 if (expected.find(opt_it.name()) == expected.end()) {
115 warning.insert(std::string(
"Warning: ") +
"Ignoring setting '" +
116 opt_it.name() +
"' (it is unrecognized or unncessary).");
117 all_necessary =
false;
120 return all_necessary;
124 auto it = parser.
self.
find(
"verbosity");
126 std::string verbosity_string;
127 if (it->is_string()) {
128 verbosity_string = it->get<std::string>();
129 }
else if (it->is_int()) {
133 return default_verbosity;
141 return default_verbosity;
144 return default_verbosity;
152 if (!header.empty()) {
159 std::string location =
"/" + pair.first.string();
160 log.
custom(std::string(
"Warnings at location: ") + location);
161 for (
const auto &msg : pair.second) {
165 if (top)
log << std::endl;
170 if (!header.empty()) {
175 for (
const auto &pair : parser.
all_errors()) {
177 std::string location =
"/" + pair.first.string();
178 log.
custom(std::string(
"Errors at location: ") + location);
179 for (
const auto &msg : pair.second) {
183 if (top)
log << std::endl;
186 namespace make_report_impl {
197 std::string sep =
".";
198 if (parser.
name().empty()) {
203 parent[parser.
name() + sep +
"WARNING"] = parser.
warning;
204 parent[parser.
name() + sep +
"WARNING"].set_force_column();
206 if (parser.
error.size()) {
207 parent[parser.
name() + sep +
"ERROR"] = parser.
error;
208 parent[parser.
name() + sep +
"ERROR"].set_force_column();
217 for (
auto const &subparser_pair : parser) {
static std::string invalid_verbosity_msg(std::string s)
void custom(const std::string &what)
static std::pair< bool, int > verbosity_level(std::string s)
Read verbosity level from a string.
iterator end()
Returns iterator to end of JSON object or JSON array.
iterator find(const std::string &name)
Return iterator to JSON object value with 'name'.
jsonParser::iterator find_at(const fs::path &path)
Return iterator to sub-object or element, or 'end' if not found.
std::string to_string(ENUM val)
Return string representation of enum class.
jsonParser & get_parent(jsonParser &report, KwargsParser const &parser)
void add_to_report(jsonParser &report, KwargsParser const &parser)
int parse_verbosity(KwargsParser &parser, int default_verbosity=10)
void print_errors(KwargsParser const &parser, Log &log, std::string header="Errors")
Formatted print error messages, including all subparsers.
void print_warnings(KwargsParser const &parser, Log &log, std::string header="Warnings")
Formatted print warning messages, including all subparsers.
jsonParser make_report(KwargsParser const &parser)
Return parser.input with error and warning messages added in place.
void parse(InputParser< ConfigEnumOptions > &parser, std::string method_name, PrimClex const &primclex, DataFormatterDictionary< Configuration > const &dict)
std::string name() const
Name of this->self, equivalent to this->path.filename().string()
bool valid() const
Return true if this and and all subparsers are valid.
KwargsParser(jsonParser const &_input, fs::path _path, bool _required)
std::map< fs::path, std::set< std::string > > all_errors() const
Return error messages from this and all subparsers.
Validator & insert(const Validator &other)
map_type::value_type PairType
map_type::const_iterator begin() const
Begin iterator over subparsers.
bool required
If this->input.at(this->path) is required to exist.
void insert_warning(fs::path option, std::string message)
Insert a subparser at location option with a single warning message
fs::path relpath(const fs::path &val) const
Return this->path / val, ensuring the result is a relative path.
jsonParser const & input
Reference to the top of the JSON document being parsed.
std::map< fs::path, std::set< std::string > > all_warnings() const
Return warning messages from this and all subparsers.
const jsonParser & parent() const
void insert_error(fs::path option, std::string message)
Insert a subparser at location option with a single error message
map_type::const_iterator end() const
End iterator over subparsers.
fs::path parent_path() const
bool warn_unnecessary(const std::set< std::string > &expected)
Insert a warning if any unexpected JSON attributes are found in self.
std::set< std::string > error
std::set< std::string > warning