mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 11:00:38 +00:00
Add json output listDevices and uploadStickerPack commands
This commit is contained in:
parent
893b7f7f9d
commit
70fc2381d3
2 changed files with 49 additions and 13 deletions
|
@ -3,6 +3,7 @@ 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;
|
||||
|
@ -15,8 +16,9 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class UploadStickerPackCommand implements LocalCommand {
|
||||
public class UploadStickerPackCommand implements JsonRpcLocalCommand {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(UploadStickerPackCommand.class);
|
||||
|
||||
|
@ -36,12 +38,17 @@ public class UploadStickerPackCommand implements LocalCommand {
|
|||
public void handleCommand(
|
||||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
final var writer = (PlainTextWriter) outputWriter;
|
||||
var path = new File(ns.getString("path"));
|
||||
|
||||
try {
|
||||
var url = m.uploadStickerPack(path);
|
||||
writer.println("{}", url);
|
||||
if (outputWriter instanceof PlainTextWriter) {
|
||||
final var writer = (PlainTextWriter) outputWriter;
|
||||
writer.println("{}", url);
|
||||
} else {
|
||||
final var writer = (JsonWriter) outputWriter;
|
||||
writer.write(Map.of("url", url));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Upload error (maybe image size too large):" + e.getMessage());
|
||||
} catch (StickerPackInvalidException e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue