summaryrefslogtreecommitdiff
path: root/modules/tools/examples/cli_mod.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/tools/examples/cli_mod.cpp')
-rw-r--r--modules/tools/examples/cli_mod.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/modules/tools/examples/cli_mod.cpp b/modules/tools/examples/cli_mod.cpp
index 84b3dc6..42d4370 100644
--- a/modules/tools/examples/cli_mod.cpp
+++ b/modules/tools/examples/cli_mod.cpp
@@ -1,6 +1,66 @@
+#include "../c++/cli_analyzer.hpp"
+#include <filesystem>
+#include <fstream>
+
+#include <iostream>
+
+namespace schema {
+using namespace saw::schema;
+
+using AnalyzeTest = Struct<
+ Member<String, "foo">
+>;
+}
int main(int argc, char** argv){
+ /**
+ * Basic checking and wrapping args into an array of string_view
+ */
+ int min_amount_args = 2;
+
+ if( argc < (min_amount_args + 1) ) {
+ std::cerr<<"Not enough arguments"<<std::endl;
+ return -1;
+ }
+
+ if(argc > 32){
+ std::cerr<<"Too many arguments"<<std::endl;
+ return -1;
+ }
+ std::array<std::string_view, 32> args_view;
+ for(int i = 0; i < argc; ++i){
+ args_view.at(i) = {argv[i]};
+ }
+
+ uint64_t args_size = [&]() -> uint64_t{
+ if(args_view.at(1) == "r"){
+ return min_amount_args;
+ }else if (args_view.at(1) == "w"){
+ return min_amount_args + 1u;
+ }
+ return 0u;
+ }();
+
+ if(args_size < min_amount_args){
+ std::cerr<<"Invalid first argument. Must either be 'r' or 'w'"<<std::endl;
+ return -1;
+ }
+
+ bool is_read_mode = [&]() -> bool {
+ if(args_view.at(1) == "w"){
+ return false;
+ }
+ return true;
+ }();
+
+ std::string json_data;
+ std::deque<std::string> sch_path;
+ int rc = saw::modify_data_on_cli<schema::AnalyzeTest, saw::encode::Json>(is_read_mode, args_view.at(2), sch_path, json_data);
+
+ for(int i = 0; i < argc; ++i){
+ std::cout<<args_view.at(i)<<std::endl;
+ }
return 0;
}