-
Notifications
You must be signed in to change notification settings - Fork 1
/
remote_bbi_options.cc
122 lines (105 loc) · 3.24 KB
/
remote_bbi_options.cc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <getopt.h>
#include <iostream>
struct opts {
std::string resource;
std::string contig;
std::string host = "localhost";
std::string port = "http";
bool print_chrom_ids = false;
bool print_main_headers = false;
bool print_zoom_headers = false;
uint32_t m = 0;
uint32_t M = 0;
uint32_t zoom_level = 0;
bool debug_session = false;
};
void usage() {
std::cerr <<
"Usage:\n"
"\t-r, --resource required (http:// or local file)\n"
"\t-c, --chrom-name (defaults fo first index)\n"
"\t-m, --min-coord (defaults to 0)\n"
"\t-M, --max-coord (defaults to 0)\n\n"
"\t-h, --host (defaults to localhost)\n"
"\t-p, --port (defaults to 80)\n"
"\t-z, --zoom (defaults to 0 i.e. main data)\n"
"\t-d, --debug-session prints the headers for the HTTP session\n\n"
"\t--print-chroms prints each chromosome, (name, id, size)\n"
"\t--print-main prints the main-headers\n"
"\t--print-zoom prints the zoom-headers\n";
}
opts parse_options(int argc, char** argv) {
opts opts;
int print = 0;
option longopts[]{
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"resource", required_argument, NULL, 'r'},
{"zoom-level", required_argument, NULL, 'z'},
{"chrom-name", required_argument, NULL, 'c'},
{"print-chroms", no_argument, &print, 1},
{"print-main", no_argument, &print, 2},
{"print-zoom", no_argument, &print, 3},
{"min-coord", required_argument, NULL, 'm'},
{"max-coord", required_argument, NULL, 'M'},
{"debug-session", no_argument, NULL, 'd'},
{NULL, 0, NULL, 0} // This is a required sentinel.
};
char c;
while ((c = getopt_long_only(argc, argv, "h:p:r:z:m:M:d", longopts, NULL)) != -1) {
switch (c) {
case 'h':
opts.host.assign(optarg);
break;
case 'p':
opts.port.assign(optarg);
break;
case 'r':
opts.resource.assign(optarg);
break;
case 'c':
opts.contig.assign(optarg);
break;
case 'z':
opts.zoom_level = std::atoi(optarg);
break;
case 'm':
opts.m = std::atoi(optarg);
break;
case 'M':
opts.M = std::atoi(optarg);
break;
case 'd':
opts.debug_session = true;
break;
case 0:
switch (print) {
case 1:
opts.print_chrom_ids = true;
break;
case 2:
opts.print_main_headers = true;
break;
case 3:
opts.print_zoom_headers = true;
break;
default:
break;
}
break;
case ':':
usage();
case '?':
usage();
default:
exit(EXIT_FAILURE);
break;
}
}
if (opts.resource.empty()) {
std::cerr << "resource is a required option.\n";
usage();
exit(EXIT_FAILURE);
}
return opts;
}