forked from rethinkdb/rethinkdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
98 lines (84 loc) · 3.56 KB
/
main.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
// Copyright 2010-2012 RethinkDB, all rights reserved.
#include <sys/resource.h>
#include <set>
#include "clustering/administration/main/command_line.hpp"
#include "clustering/administration/cli/admin_command_parser.hpp"
#include "utils.hpp"
#include "help.hpp"
#include "config/args.hpp"
void print_version_message() {
printf("%s\n", RETHINKDB_VERSION_STR);
}
int main(int argc, char *argv[]) {
install_generic_crash_handler();
#ifndef NDEBUG
rlimit core_limit;
core_limit.rlim_cur = 100 * MEGABYTE;
core_limit.rlim_max = 200 * MEGABYTE;
setrlimit(RLIMIT_CORE, &core_limit);
#endif
std::set<std::string> subcommands_that_look_like_flags;
subcommands_that_look_like_flags.insert("--version");
subcommands_that_look_like_flags.insert("--help");
subcommands_that_look_like_flags.insert("-h");
if (argc == 1 || (argv[1][0] == '-' && subcommands_that_look_like_flags.count(argv[1]) == 0)) {
return main_rethinkdb_porcelain(argc, argv);
} else {
std::string subcommand = argv[1];
if (subcommand == "create") {
return main_rethinkdb_create(argc, argv);
} else if (subcommand == "serve") {
return main_rethinkdb_serve(argc, argv);
} else if (subcommand == "proxy") {
return main_rethinkdb_proxy(argc, argv);
} else if (subcommand == "admin") {
return main_rethinkdb_admin(argc, argv);
} else if (subcommand == "import") {
return main_rethinkdb_import(argc, argv);
} else if (subcommand == "--version") {
if (argc != 2) {
puts("WARNING: Ignoring extra parameters after '--version'.");
}
print_version_message();
return 0;
} else if (subcommand == "help" || subcommand == "-h" || subcommand == "--help") {
if (argc == 2) {
puts("'rethinkdb' is divided into a number of subcommands:");
puts("");
puts(" 'rethinkdb create': prepare files on disk");
puts(" 'rethinkdb serve': serve queries and host data");
puts(" 'rethinkdb proxy': serve queries but don't host data");
puts(" 'rethinkdb admin': access and modify cluster metadata");
puts(" 'rethinkdb import': import data from from a file");
puts("");
puts("For more information, run 'rethinkdb help [subcommand]'.");
return 0;
} else if (argc == 3) {
std::string subcommand2 = argv[2];
if (subcommand2 == "create") {
help_rethinkdb_create();
return 0;
} else if (subcommand2 == "serve") {
help_rethinkdb_serve();
return 0;
} else if (subcommand2 == "admin") {
admin_command_parser_t::do_usage(false);
return 0;
} else if (subcommand2 == "proxy") {
help_rethinkdb_proxy();
} else if (subcommand2 == "import") {
help_rethinkdb_import();
} else {
printf("ERROR: No help for '%s'\n", subcommand2.c_str());
return 1;
}
} else {
puts("ERROR: Too many parameters to 'rethinkdb help'. Try 'rethinkdb help [subcommand]'.");
return 1;
}
} else {
puts("ERROR: Unrecognized subcommand ''. Try 'rethinkdb help'.");
return 1;
}
}
}