149{
150
151
152
153
154
155
156
157
158
160 {
161 std::unique_ptr<BackendSection> backend;
162 std::vector<ActionSection> pre;
163 std::vector<ActionSection> post;
164 };
165
167
168
169 std::map<std::string, std::function<void(const std::string &arg)>> argparse;
170
171 argparse["--backend"] = [§ions](const std::string &tag) {
172 sections.backend = std::make_unique<BackendSection>(tag);
173 };
174
175 argparse[
"--backend-arg"] = [§ions](
const std::string &
arg) {
176 sections.backend->append(arg);
177 };
178
179 argparse["--pre"] = [§ions](const std::string &tag) { sections.pre.emplace_back(tag); };
180
181 argparse[
"--pre-arg"] = [§ions](
const std::string &
arg) { sections.pre.back().append(arg); };
182
183 argparse["--post"] = [§ions](const std::string &tag) { sections.post.emplace_back(tag); };
184
185 argparse[
"--post-arg"] = [§ions](
const std::string &
arg) {
186 sections.post.back().append(arg);
187 };
188
189 if (argc < 2)
190 {
191 std::cerr << "Usage:" << std::endl
192 << "[Command] --backend [Backend module path] "
193 << "--backend-arg [Backend argument] ..." << std::endl
194 << " --pre [Pre-Action module path] "
195 << "--pre-arg [Pre-Action argument] ..." << std::endl
196 << " --post [Post-Action module path] "
197 << "--post-arg [Post-Action argument] ..." << std::endl;
198 return 255;
199 }
200
201 for (
int n = 1; n <
argc; n += 2)
202 {
203 const std::string tag{
argv[n]};
204 const std::string
arg{
argv[n + 1]};
205
206 auto it = argparse.find(tag);
207
208 if (it == argparse.end())
209 {
210 std::cerr << "Option '" << tag << "' is not supported" << std::endl;
211 return 255;
212 }
213
214 it->second(arg);
215 }
216
217
218 if (sections.backend == nullptr)
219 {
220 std::cerr << "Error: Backend is required. Provide with [--backend]" << std::endl;
221 return 255;
222 }
223
224
225 auto backend = sections.backend->initialize();
226
227
228 std::vector<std::unique_ptr<nnkit::Action>> pre_actions;
229
230 for (const auto §ion : sections.pre)
231 {
232 pre_actions.emplace_back(section.initialize());
233 }
234
235
236 std::vector<std::unique_ptr<nnkit::Action>> post_actions;
237
238 for (const auto §ion : sections.post)
239 {
240 post_actions.emplace_back(section.initialize());
241 }
242
243
244
245
247
248 for (auto &action : pre_actions)
249 {
251 }
252 });
253
254 backend->run();
255
257
258 for (auto &action : post_actions)
259 {
261 }
262 });
263
264 return 0;
265}
std::vector< Section > Sections