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

Method help

3rdparty/libprocess/src/help.cpp:194–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192
193
194Future<http::Response> Help::help(const http::Request& request)
195{
196 // Path format of the url: /help/<id>[/<name>].
197 // Note that <name> may contain slashes.
198 vector<string> tokens = strings::tokenize(request.url.path, "/", 3);
199
200 Option<string> id = None();
201 Option<string> name = None();
202
203 if (tokens.size() > 1) {
204 id = tokens[1];
205 }
206
207 if (tokens.size() > 2) {
208 name = tokens[2];
209 }
210
211 string document;
212 string references;
213
214 if (id.isNone()) { // http://ip:port/help
215 // If the request query string has format=json, return the JSON
216 // representation of the helps strings.
217 //
218 // NOTE: We avoided relying on the 'Accept' header to specify the
219 // format because if users are hitting the endpoint from a browser
220 // it is difficult to change the 'Accept' header.
221 //
222 // TODO(klueska): add the ability for all /help/* endpoints to be
223 // returned as json, not just /help.
224 if (request.url.query.get("format") == Some("json")) {
225 return http::OK(jsonify(*this));
226 }
227
228 document += "## HELP\n";
229 foreachkey (const string& id, helps) {
230 document += "> [/" + id + "][" + id + "]\n";
231 references += "[" + id + "]: help/" + id + "\n";
232 }
233 } else if (name.isNone()) { // http://ip:port/help/id
234 if (helps.count(id.get()) == 0) {
235 return http::BadRequest(
236 "No help available for '/" + id.get() + "'.\n");
237 }
238
239 document += "## `/" + id.get() + "` ##\n";
240 foreachkey (const string& name, helps[id.get()]) {
241 const string path = getUsagePath(id.get(), name);
242 document += "> [/" + path + "][" + path + "]\n";
243 references += "[" + path + "]: " + path + "\n";
244 }
245 } else { // http://ip:port/help/id/name
246 if (helps.count(id.get()) == 0) {
247 return http::BadRequest(
248 "No help available for '/" + id.get() + "'.\n");
249 } else if (helps[id.get()].count("/" + name.get()) == 0) {
250 return http::BadRequest(
251 "No help available for '/" + id.get() + "/" + name.get() + "'.\n");

Callers

nothing calls this directly

Calls 14

tokenizeFunction · 0.85
NoneClass · 0.85
SomeFunction · 0.85
OKClass · 0.85
jsonifyFunction · 0.85
BadRequestClass · 0.85
startsWithFunction · 0.85
StringClass · 0.85
stringifyClass · 0.50
sizeMethod · 0.45
isNoneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected