6 #include <boost/property_tree/ptree.hpp>
7 #include <boost/property_tree/json_parser.hpp>
8 #include "private/cli/commandmap.hpp"
9 #include "private/configurationpaths.hpp"
10 #include "private/configurationreader.hpp"
12 using namespace shareddatalayer;
13 using namespace shareddatalayer::cli;
17 bool parseConfiguration(const std::string& file)
19 boost::property_tree::ptree propertyTree;
23 boost::property_tree::read_json(file, propertyTree);
25 catch (const boost::property_tree::json_parser::json_parser_error& e)
27 std::ostringstream os;
28 os << "error in SDL configuration " << file << " at line " << e.line() << ": ";
30 std::cerr << os.str().c_str() << std::endl;
37 int dumpConfigurationCommand(std::ostream& out)
42 for (const auto& i : findConfigurationFiles( getDefaultConfDirectories() ))
44 std::ifstream file(i);
46 out << "File: " << i << std::endl;
48 unsigned int lineNum = 1;
52 bool parseStatus = parseConfiguration(i);
54 if(status && !parseStatus)
57 while(getline(file, line))
58 out << lineNum++ << ": " << line << std::endl;
63 const auto var(DB_HOST_ENV_VAR_NAME);
64 const auto conf(getenv(var));
66 out << var << " not set." << std::endl;
68 out << var << ": " << conf << std::endl;
78 AUTO_REGISTER_COMMAND(std::bind(dumpConfigurationCommand, std::placeholders::_1),
81 "Find, parse and dump all shareddatalayer configuration files contents.",
82 CommandMap::Category::UTIL, 30000);