-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenomic.cpp
106 lines (83 loc) · 2.3 KB
/
genomic.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
95
96
97
98
99
100
101
102
103
104
105
106
#include <cstdlib>
#include <fstream>
#include <vector>
#include <map>
#include <stdexcept>
using namespace std;
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include "genomic.hpp"
int main(int argc, char **argv)
{
typedef map<string, Command*> CommandMap;
Command* command = NULL;
CommandMap commands;
bool printUsage = false;
bool printVersion = false;
int ret = 0;
try {
commands["convert"] = new Convert();
commands["filter"] = new Filter();
commands["clean"] = new Clean();
commands["sort"] = new Sort();
// Use the first argument (excluding name of program itself)
// to determine the command
if (argc < 2) {
printUsage = true;
} else {
string s = argv[1];
if (s == "--help" || s == "-h") {
printUsage = true;
} else if (s == "--version" || s == "-v") {
printVersion = true;
} else {
CommandMap::iterator it;
CommandMap::const_iterator end = commands.end();
for (it = commands.begin(); it != end; ++it) {
if (s == it->first) {
command = it->second;
break;
}
}
if (!command) {
string err;
err += "Error: '" + s + "' is an unrecognized command.";
throw runtime_error(err);
}
}
}
if (command) {
// forward remaining command line arguments
// for parsing by specified command module, and run the module
(*command).parse(argc-1, argv+1).run();
}
if (printUsage) {
cout << "usage: " << progname << " <command> [<args>]" << endl;
cout << endl;
cout << "commands:" << endl;
CommandMap::iterator it;
CommandMap::const_iterator end = commands.end();
for (it = commands.begin(); it != end; ++it) {
cout << " " << it->first << " \t"
<< *(it->second) << endl;
}
cout << endl;
cout << "See '" << progname << " <command> --help' for more information on a specific command." << endl;
}
if (printVersion) {
cout << "genomic version "
<< genomic_VERSION_MAJOR << '.' << genomic_VERSION_MINOR
<< endl;
}
} catch (const exception& e) {
cout << e.what() << endl;
ret = 1;
}
// clear command objects
CommandMap::iterator cmdIt;
CommandMap::const_iterator cmdEnd = commands.end();
for (cmdIt = commands.begin(); cmdIt != cmdEnd; ++cmdIt) {
delete cmdIt->second;
}
return ret;
}