diff options
Diffstat (limited to 'modules/tools/examples')
-rw-r--r-- | modules/tools/examples/cli_mod.cpp | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/modules/tools/examples/cli_mod.cpp b/modules/tools/examples/cli_mod.cpp index f108394..404b2ef 100644 --- a/modules/tools/examples/cli_mod.cpp +++ b/modules/tools/examples/cli_mod.cpp @@ -83,12 +83,14 @@ int main(int argc, char** argv){ return min_amount_args; }else if (args_view.at(1) == "w"){ return min_amount_args + 1u; + }else if (args_view.at(1) == "l"){ + return min_amount_args; } return 0u; }(); if(args_size < min_amount_args){ - std::cerr<<"Invalid first argument. Must either be 'r' or 'w'"<<std::endl; + std::cerr<<"Invalid first argument. Must either be 'r', 'w' or 'l'."<<std::endl; return -1; } @@ -97,21 +99,18 @@ int main(int argc, char** argv){ return -1; } - bool is_read_mode = [&]() -> bool { - if(args_view.at(1) == "w"){ - return false; - } - return true; + std::string_view mode = [&]() -> std::string_view { + return args_view.at(1); }(); std::string json_data; - if ( not is_read_mode ){ + if ( mode == "w" ){ json_data = std::string{args_view.at(4)}; } std::deque<std::string> sch_path = split_schema_path(args_view.at(3)); { - auto eov = saw::modify_data_on_cli<schema::AnalyzeTest, saw::encode::Json>(is_read_mode, args_view.at(2), sch_path, json_data); + auto eov = saw::modify_data_on_cli<schema::AnalyzeTest, saw::encode::Json>(mode, args_view.at(2), sch_path, json_data); if(eov.is_error()){ auto& err = eov.get_error(); std::cerr<<"Modification failed: "<<err.get_category()<<" - "<<err.get_message()<<std::endl; @@ -119,15 +118,9 @@ int main(int argc, char** argv){ } } - if( is_read_mode ){ + if( mode == "r" or mode == "l" ){ std::cout<<json_data<<std::endl; } -/* - for(int i = 0; i < argc; ++i){ - std::cout<<args_view.at(i)<<std::endl; - } -*/ - return 0; } |