Sha256: bcfc696fbc6f86a2b4f13d3371262bccc698e30634d95f1e68d7426cd1a14512
Contents?: true
Size: 1.47 KB
Versions: 16
Compression:
Stored size: 1.47 KB
Contents
#include <internal/facts/external/text_resolver.hpp> #include <facter/facts/collection.hpp> #include <facter/facts/scalar_value.hpp> #include <leatherman/file_util/file.hpp> #include <leatherman/logging/logging.hpp> #include <leatherman/locale/locale.hpp> #include <boost/algorithm/string.hpp> // Mark string for translation (alias for leatherman::locale::format) using leatherman::locale::_; using namespace std; namespace lth_file = leatherman::file_util; namespace facter { namespace facts { namespace external { bool text_resolver::can_resolve(string const& path) const { return boost::iends_with(path, ".txt"); } void text_resolver::resolve(string const& path, collection& facts) const { LOG_DEBUG("resolving facts from text file \"{1}\".", path); if (!lth_file::each_line(path, [&facts](string& line) { auto pos = line.find('='); if (pos == string::npos) { LOG_DEBUG("ignoring line in output: {1}", line); return true; } // Add as a string fact string fact = line.substr(0, pos); boost::to_lower(fact); facts.add_external(move(fact), make_value<string_value>(line.substr(pos+1))); return true; })) { throw external_fact_exception(_("file could not be opened.")); } LOG_DEBUG("completed resolving facts from text file \"{1}\".", path); } }}} // namespace facter::facts::external
Version data entries
16 entries across 16 versions & 2 rubygems