MCPcopy Create free account
hub / github.com/apache/mesos / main

Function main

src/cli/mesos.cpp:75–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75int main(int argc, char** argv)
76{
77 Option<string> value;
78
79 // Try and add the absolute dirname of argv[0] to PATH so we can
80 // find commands (since our installation directory might not be on
81 // the path).
82 Result<string> realpath = os::realpath(Path(argv[0]).dirname());
83 if (realpath.isSome()) {
84 value = os::getenv("PATH");
85 if (value.isSome()) {
86 os::setenv("PATH", realpath.get() + ":" + value.get());
87 } else {
88 os::setenv("PATH", realpath.get());
89 }
90 }
91
92 if (argc < 2) {
93 usage(argv[0]);
94 return EXIT_FAILURE;
95 }
96
97 // Update PYTHONPATH to include path to installed 'mesos' module.
98 // TODO(benh): Remove this if/when we install the 'mesos' module via
99 // PIP and setuptools.
100 string path = path::join(PKGLIBEXECDIR, "python");
101 value = os::getenv("PYTHONPATH");
102 if (value.isSome()) {
103 os::setenv("PYTHONPATH", value.get() + ":" + path);
104 } else {
105 os::setenv("PYTHONPATH", path);
106 }
107
108 // Now dispatch to any mesos-'command' on PATH.
109 if (string(argv[1]) == "help") {
110 if (argc == 2) {
111 usage(argv[0]);
112 return EXIT_SUCCESS;
113 } else {
114 // 'mesos help command' => 'mesos command --help'
115 argv[1] = argv[2];
116 argv[2] = (char*) "--help";
117 return main(argc, argv);
118 }
119 } else if (string(argv[1]).find("--") == 0) {
120 cerr << "Not expecting '" << argv[1] << "' before command" << endl;
121 usage(argv[0]);
122 return EXIT_FAILURE;
123 } else {
124 string command = argv[1];
125 if (command == "slave") {
126 cerr << "WARNING: subcommand 'slave' is deprecated in favor of 'agent'."
127 << endl
128 << endl;
129 }
130 string executable = "mesos-" + command;
131 argv[1] = (char*) executable.c_str();
132 execvp(executable.c_str(), argv + 1);

Callers

nothing calls this directly

Calls 12

PathClass · 0.85
strerrorFunction · 0.85
dirnameMethod · 0.80
usageFunction · 0.70
realpathFunction · 0.50
getenvFunction · 0.50
setenvFunction · 0.50
joinFunction · 0.50
execvpFunction · 0.50
isSomeMethod · 0.45
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected