blob: 42d4370fb795a905ab9ac89fdc1c66e8dc3d0564 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
}
|