This repository was archived by the owner on Dec 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (74 loc) · 2.23 KB
/
main.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <string>
#include <vector>
#include <boost/program_options.hpp>
#include "launch.h"
#include "version.h"
using namespace std;
namespace po = boost::program_options;
void print_global_help(po::options_description options)
{
cout << "Usage: " << "\n";
cout << " dextr [options] <command>" << "\n";
cout << "Commands:" << "\n";
cout << " launch execute tasks from taskfile" << "\n";
cout << " filter filter tasks logs from logfile" << "\n";
cout << options;
}
int main(int argc, char **argv)
{
// Parse commands and global options
po::options_description options("Options");
options.add_options()
("version,v", "print version string")
("help,h", "show this help message");
if (argc == 1) {
print_global_help(options);
return 1;
}
po::options_description args("Arguments");
args.add_options()
("command", po::value<string>(), "command")
("subargs", po::value<vector<string> >(), "arguments for command");
po::options_description desc;
desc.add(args).add(options);
po::positional_options_description pos;
pos.add("command", 1);
pos.add("subargs", -1);
po::variables_map vm;
po::parsed_options parsed = po::command_line_parser(argc, argv).
options(desc).
positional(pos).
allow_unregistered().
run();
try {
po::store(parsed, vm);
if (vm.count("help") and !vm.count("command")) {
print_global_help(options);
return 1;
}
if (vm.count("version")) {
cout << version << "\n";
return 1;
}
po::notify(vm);
} catch (const po::error &e) {
cerr << e.what() << "\n";
return 1;
}
string cmd = vm["command"].as<string>();
if (cmd == "launch") {
string taskfile = launch::parse_launch_options(argc-1, &argv[1]);
launch::run_cmd(taskfile);
} else if (cmd == "filter") {
// TODO:
//parse_filter_options();
//filter();
cout << "filter command not implemented" << "\n";
return 1;
} else {
print_global_help(options);
return 1;
}
return 0;
}