Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 1 | #include <string> |
| 2 | #include <vector> |
| 3 | |
| 4 | #include "aos/configuration.h" |
| 5 | #include "aos/init.h" |
| 6 | #include "aos/json_to_flatbuffer.h" |
| 7 | #include "aos/util/file.h" |
| 8 | #include "gflags/gflags.h" |
| 9 | #include "glog/logging.h" |
| 10 | |
| 11 | namespace aos { |
| 12 | |
| 13 | int Main(int argc, char **argv) { |
| 14 | CHECK_GE(argc, 3) << ": Too few arguments"; |
| 15 | |
| 16 | VLOG(1) << "Reading " << argv[2]; |
| 17 | FlatbufferDetachedBuffer<Configuration> config = |
| 18 | configuration::ReadConfig(argv[2]); |
| 19 | |
| 20 | std::vector<aos::FlatbufferString<reflection::Schema>> schemas; |
| 21 | |
| 22 | for (int i = 3; i < argc; ++i) { |
| 23 | schemas.emplace_back(util::ReadFileToStringOrDie(argv[i])); |
| 24 | } |
| 25 | |
| 26 | const std::string merged_config = FlatbufferToJson( |
| 27 | &configuration::MergeConfiguration(config, schemas).message(), true); |
| 28 | |
| 29 | // TODO(austin): Figure out how to squash the schemas onto 1 line so it is |
Brian Silverman | 8533bac | 2020-01-31 17:44:27 -0800 | [diff] [blame] | 30 | // easier to read? |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 31 | VLOG(1) << "Flattened config is " << merged_config; |
| 32 | util::WriteStringToFileOrDie(argv[1], merged_config); |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | } // namespace aos |
| 37 | |
| 38 | int main(int argc, char **argv) { |
| 39 | aos::InitGoogle(&argc, &argv); |
| 40 | return aos::Main(argc, argv); |
| 41 | } |