MPS-Basic
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include "common.hpp"
2#include "simulation.hpp"
3
4#include <argparse/argparse.hpp>
5#include <filesystem>
6
7using std::cerr;
8using std::cout;
9using std::endl;
10namespace fs = std::filesystem;
11
19int main(int argc, char** argv) {
20 argparse::ArgumentParser program("mps");
21
22 program.add_argument("-s", "--setting")
23 .required()
24 .help("path to setting file")
25 .action([](const std::string& value) {
26 if (!fs::exists(value)) {
27 cout << "ERROR: The setting file " << value << " does not exist" << endl;
28 cerr << "ERROR: The setting file " << value << " does not exist" << endl;
29 exit(-1);
30 }
31 cout << "Setting file: " << value << endl;
32 return value;
33 });
34
35 program.add_argument("-o", "--output")
36 .required()
37 .help("path to output directory")
38 .action([](const std::string& value) {
39 if (!fs::exists(value)) {
40 cout << "ERROR: The output directory " << value << " does not exist" << endl;
41 cerr << "ERROR: The output directory " << value << " does not exist" << endl;
42 exit(-1);
43 }
44 cout << "Output directory: " << value << endl;
45 fs::create_directories(value);
46 return value;
47 });
48
49 // Although the use of exeptions is prohibited by the guidelines of this project,
50 // the following process is shown in the document of the argpase library,
51 // so we use here as an execptional calse.
52 try {
53 program.parse_args(argc, argv);
54 } catch (const std::exception& err) {
55 cout << err.what() << endl;
56 cerr << err.what() << endl;
57 cerr << program;
58 exit(-1);
59 }
60
61 // auto settingPath = fs::path(argv[1]);
62 auto settingPath = fs::path(program.get<std::string>("--setting"));
63 auto outputDirectory = fs::path(program.get<std::string>("--output"));
64 Simulation simulation(settingPath, outputDirectory);
65 simulation.run();
66
67 return 0;
68}
int main(int argc, char **argv)
entry point of the program
Definition main.cpp:19