-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (67 loc) · 2.07 KB
/
main.cpp
File metadata and controls
75 lines (67 loc) · 2.07 KB
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
67
68
69
70
71
72
73
74
75
//
// main.cpp
// Workflow
//
// Created by Кирилл on 20.11.17.
// Copyright © 2017 Кирилл. All rights reserved.
//
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "workflow.h"
int main(int argc, const char* argv[]) {
std::vector<std::string> args(argv + 1, argv + argc);
std::string inputFilename;
std::string outputFilename;
std::string workflowInput;
// Разбор аргументов командной строки
for (auto i = args.begin(); i < args.end(); i++) {
if ((*i)[0] != '-') { // Не название опции
if (workflowInput != "") {
std::cerr << "To many workflow input files." << std::endl;
return 1;
}
workflowInput = *i;
} else if ((i + 1) == args.end() ||
(*(i + 1))[0] == '-') { // Опции с аргументами
std::cerr << "Option " << *i << " is not set." << std::endl;
return 1;
} else if ((*i) == "-i") {
if (inputFilename != "") {
std::cerr << "To many input files." << std::endl;
return 1;
}
inputFilename = *++i;
} else if ((*i) == "-o") {
if (outputFilename != "") {
std::cerr << "To many output files." << std::endl;
return 1;
}
outputFilename = *++i;
} else {
std::cerr << "Unknown option: " << *i << std::endl;
return 1;
}
}
// Проверка наличия параметров
if (workflowInput == "") {
std::cerr << "No workflow input file." << std::endl;
return 1;
}
std::ifstream file(workflowInput);
if (!file.is_open()) {
std::cerr << "Cannot open file: \"" << workflowInput << "\"" << std::endl;
return 1;
}
try {
wkfw::Workflow workflow(file, inputFilename, outputFilename);
workflow.execute();
} catch (const wkfw::InvalidWorkflowException& e) {
std::cerr << "InvalidWorkflowException: " << e.what() << std::endl;
} catch (const wkfw::WorkerExecuteException& e) {
std::cerr << "WorkerExecuteException: " << e.what() << std::endl;
}
file.close();
return 0;
}