#include "SoilMoistureIo.h" #include "json.hpp" #include "apps.h" enum class Format { PLAIN, JSON, SQL }; void validate(boost::any &v, const std::vector &values, Format *, int) { using namespace boost::program_options; const std::string &s = validators::get_single_string(values); if (s == "plain") { v = boost::any(Format::PLAIN); } else if (s == "json") { v = boost::any(Format::JSON); } else if (s == "sql") { v = boost::any(Format::SQL); } else { throw validation_error(validation_error::invalid_option_value); } } namespace boost { template<> std::string lexical_cast(const Format &arg) { if (arg == Format::PLAIN) return "plain"; else if (arg == Format::JSON) return "json"; else if (arg == Format::SQL) return "sql"; else throw std::runtime_error("Unknown format value: " + lexical_cast(arg)); } } namespace trygvis { namespace apps { using namespace std; using namespace trygvis::apps; using namespace trygvis::soil_moisture; namespace po = boost::program_options; Format inputFormat, outputFormat; class sample_convert : public app { public: // void add_options(po::options_description_easy_init &options) override { // options // ("help", "produce help message") // ("input-format", po::value(&inputFormat)->default_value(Format::PLAIN)) // ("output-format", po::value(&outputFormat)->default_value(Format::PLAIN)) // } int main(app_execution &execution) override { auto desc = execution.desc; auto vm = execution.vm; shared_ptr sampleStream; auto field_names = vector({ "hostname", "device_type", "device", "timestamp", "sensor", "value" }); sampleStream = make_shared(cout, field_names); map values; values["hostname"] = "my-hostname"; values["extra"] = "wat"; sampleStream->write(values); return EXIT_SUCCESS; } }; } } using namespace trygvis::apps; int main(int argc, char *argv[]) { sample_convert app; return launch_app(argc, argv, app); }