From 399d0a9a02d4a993b20637bebfba22f4c33aff04 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 6 May 2024 14:36:55 +0200 Subject: Reworking the cli manipulator a little bit --- modules/tools/c++/cli_analyzer.hpp | 12 +++++++++--- modules/tools/examples/cli_mod.cpp | 23 ++++++++--------------- 2 files changed, 17 insertions(+), 18 deletions(-) (limited to 'modules') diff --git a/modules/tools/c++/cli_analyzer.hpp b/modules/tools/c++/cli_analyzer.hpp index 6b44987..8142e2a 100644 --- a/modules/tools/c++/cli_analyzer.hpp +++ b/modules/tools/c++/cli_analyzer.hpp @@ -14,6 +14,7 @@ namespace impl { struct cli_mode { struct read {}; struct write {}; + struct list {}; }; template @@ -167,7 +168,7 @@ struct parsed_args { }; template -error_or modify_data_on_cli(bool read_mode, const std::string_view& file_path, std::deque sch_path, std::string& json_data){ +error_or modify_data_on_cli(const std::string_view& mode, const std::string_view& file_path, std::deque sch_path, std::string& json_data){ /** * Read data from file */ @@ -194,14 +195,14 @@ error_or modify_data_on_cli(bool read_mode, const std::string_view& file_p } } - if (read_mode) { + if (mode == "r") { { auto eov = impl::cli_traverser>::template traverse(sch_path, native_data, json_data); if(eov.is_error()){ return eov; } } - } else { + } else if (mode == "w") { { auto eov = impl::cli_traverser>::template traverse(sch_path, native_data, json_data); if(eov.is_error()){ @@ -225,6 +226,11 @@ error_or modify_data_on_cli(bool read_mode, const std::string_view& file_p fstr << enc_str; fstr.close(); } + } else if (mode == "l"){ + { + } + }else{ + return make_error("Invalid mode"); } return void_t{}; 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'"< 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 sch_path = split_schema_path(args_view.at(3)); { - auto eov = saw::modify_data_on_cli(is_read_mode, args_view.at(2), sch_path, json_data); + auto eov = saw::modify_data_on_cli(mode, args_view.at(2), sch_path, json_data); if(eov.is_error()){ auto& err = eov.get_error(); std::cerr<<"Modification failed: "<