mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Add listAccounts command
This commit is contained in:
parent
9c67aabebb
commit
62dd2ee49e
4 changed files with 50 additions and 1 deletions
|
@ -17,6 +17,7 @@ public class Commands {
|
|||
addCommand(new JoinGroupCommand());
|
||||
addCommand(new JsonRpcDispatcherCommand());
|
||||
addCommand(new LinkCommand());
|
||||
addCommand(new ListAccountsCommand());
|
||||
addCommand(new ListContactsCommand());
|
||||
addCommand(new ListDevicesCommand());
|
||||
addCommand(new ListGroupsCommand());
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.JsonWriter;
|
||||
import org.asamk.signal.OutputWriter;
|
||||
import org.asamk.signal.PlainTextWriter;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ListAccountsCommand implements JsonRpcMultiLocalCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "listAccounts";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.help("Show a list of registered accounts.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(
|
||||
final Namespace ns, final SignalCreator c, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
final var accountNumbers = c.getAccountNumbers();
|
||||
if (outputWriter instanceof JsonWriter jsonWriter) {
|
||||
final var jsonAccounts = accountNumbers.stream().map(JsonAccount::new).collect(Collectors.toList());
|
||||
jsonWriter.write(jsonAccounts);
|
||||
} else if (outputWriter instanceof PlainTextWriter plainTextWriter) {
|
||||
for (final var number : accountNumbers) {
|
||||
plainTextWriter.println("Number: {}", number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private record JsonAccount(String number) {}
|
||||
}
|
|
@ -119,7 +119,7 @@ public class SignalJsonRpcDispatcherHandler {
|
|||
final ObjectMapper objectMapper, final String method, ContainerNode<?> params
|
||||
) throws JsonRpcException {
|
||||
var command = getCommand(method);
|
||||
// TODO implement listAccounts, register, verify, link
|
||||
// TODO implement register, verify, link
|
||||
if (c != null && command instanceof JsonRpcMultiCommand<?> jsonRpcCommand) {
|
||||
return runCommand(objectMapper, params, new MultiCommandRunnerImpl<>(c, jsonRpcCommand));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue