philadelphia-client: Improve 'messages' command
@@ -4,17 +4,31 @@ import com.paritytrading.philadelphia.client.TerminalClient;
import com.paritytrading.philadelphia.client.message.Message;
import com.paritytrading.philadelphia.client.message.Messages;
import java.util.Scanner;
+import org.eclipse.collections.api.list.ImmutableList;
class MessagesCommand implements Command {
@Override
public void execute(TerminalClient client, Scanner arguments) throws CommandException {
+ if (arguments.hasNext()) {
+ int index = arguments.nextInt();
+
+ ImmutableList<Message> messages = client.getMessages().collect();
+
+ if (index >= 0 && index < +messages.size())
+ client.printf("%s\n", messages.get(index));
+
+ if (index >= -messages.size() && index < 0)
+ client.printf("%s\n", messages.get(index + messages.size()));
+
if (arguments.hasNext())
throw new CommandException();
-
+ }
+ else {
for (Message message : client.getMessages().collect())
client.printf("%s\n", message);
}
+ }
@Override
public String getName() {
@@ -28,7 +42,7 @@ class MessagesCommand implements Command {
@Override
public String getUsage() {
- return "messages";
+ return "messages [<index>]";
}
}
