-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpih.cc
61 lines (53 loc) · 1.35 KB
/
mpih.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
#include "Command/commands.h"
#include "Options/CommonOptions.h"
#include "Env/env.h"
#include "IO/IOUtil.h"
#include <string>
#include <sstream>
#include <getopt.h>
using namespace std;
static const char main_shortopts[] = "+hs:v";
static const struct option main_longopts[] = {
{ "help", no_argument, NULL, 'h' },
{ "socket", required_argument, NULL, 's' },
{ "verbose", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
int main(int argc, char** argv)
{
if (getenv(MPIH_SOCKET))
opt::socketPath = getenv(MPIH_SOCKET);
for (int c; (c = getopt_long(argc, argv,
main_shortopts, main_longopts, NULL)) != -1;) {
std::istringstream arg(optarg != NULL ? optarg : "");
switch (c) {
case '?':
die(USAGE_MESSAGE);
case 'h':
arg >> opt::help; break;
case 's':
arg >> opt::socketPath; break;
case 'v':
opt::verbose++; break;
}
if (optarg != NULL && (!arg.eof() || arg.fail())) {
std::cerr << "mpih: invalid option: `-"
<< (char)c << optarg << "'\n";
return EXIT_FAILURE;
}
}
string command;
if (argc - optind > 0)
command = argv[optind++];
if (opt::socketPath.empty() &&
command != "version" &&
command != "--version" &&
command != "help" &&
!opt::help &&
command != "run")
{
std::cerr << "error: no socket path specified\n";
die(USAGE_MESSAGE);
}
return invoke_cmd(command.c_str(), argc, argv);
}