Skip to content

Commit 28eff2b

Browse files
committed
remove help command, list all cat commands in /_cat?h endpoint
1 parent 0e78404 commit 28eff2b

File tree

4 files changed

+22
-57
lines changed

4 files changed

+22
-57
lines changed

docs/reference/cat.asciidoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ to find relationships in the data is tedious. Human eyes, especially
1212
when looking at an ssh terminal, need compact and aligned text. The
1313
cat API aims to meet this need.
1414

15+
All the cat commands accept a query string parameter `h` to see all
16+
the headers and info they provide, and the `/_cat?h` command lists all
17+
the available commands.
18+
1519
[float]
1620
[[common-parameters]]
1721
== Common parameters
@@ -45,7 +49,7 @@ by all the shards, not number of documents). The `/_cat/indices` API
4549
is ideal. We only need to tweak two things. First, we want to turn
4650
off human mode. We'll use a byte-level resolution. Then we'll pipe
4751
our output into `sort` using the appropriate column, which in this
48-
case is the eigth one.
52+
case is the eight one.
4953

5054
[source,shell]
5155
--------------------------------------------------

src/main/java/org/elasticsearch/rest/action/RestActionModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,5 @@ protected void configure() {
222222
catActionMultibinder.addBinding().to(org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction.class).asEagerSingleton();
223223
// no abstract cat action
224224
bind(RestCatAction.class).asEagerSingleton();
225-
bind(RestHelpAction.class).asEagerSingleton();
226225
}
227226
}

src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,37 @@
2525
import org.elasticsearch.rest.*;
2626

2727
import java.io.IOException;
28+
import java.util.Set;
2829

2930
import static org.elasticsearch.rest.RestRequest.Method.GET;
3031

3132
public class RestCatAction extends BaseRestHandler {
3233

33-
private static final String CAT = "=^.^=\n";
34+
private static final String CAT = "=^.^=";
35+
private static final String CAT_NL = CAT + "\n";
36+
private final String HELP;
3437

3538
@Inject
36-
public RestCatAction(Settings settings, Client client, RestController controller) {
39+
public RestCatAction(Settings settings, Client client, RestController controller, Set<AbstractCatAction> catActions) {
3740
super(settings, client);
3841
controller.registerHandler(GET, "/_cat", this);
42+
StringBuilder sb = new StringBuilder();
43+
sb.append(CAT).append(" try:\n");
44+
for (AbstractCatAction catAction : catActions) {
45+
catAction.documentation(sb);
46+
}
47+
HELP = sb.toString();
3948
}
4049

4150
@Override
4251
public void handleRequest(final RestRequest request, final RestChannel channel) {
4352
try {
44-
channel.sendResponse(new StringRestResponse(RestStatus.OK, CAT));
53+
boolean helpWanted = request.paramAsBoolean("h", false);
54+
if (helpWanted) {
55+
channel.sendResponse(new StringRestResponse(RestStatus.OK, HELP));
56+
} else {
57+
channel.sendResponse(new StringRestResponse(RestStatus.OK, CAT_NL));
58+
}
4559
} catch (Throwable t) {
4660
try {
4761
channel.sendResponse(new XContentThrowableRestResponse(request, t));

src/main/java/org/elasticsearch/rest/action/cat/RestHelpAction.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)