Small improvements

This commit is contained in:
AsamK 2022-11-01 21:57:23 +01:00
parent 2e4d346bc8
commit 43face8ead
12 changed files with 35 additions and 35 deletions

View file

@ -11,11 +11,11 @@ public class Commands {
static {
addCommand(new AddDeviceCommand());
addCommand(new GetAttachmentCommand());
addCommand(new BlockCommand());
addCommand(new DaemonCommand());
addCommand(new DeleteLocalAccountDataCommand());
addCommand(new FinishLinkCommand());
addCommand(new GetAttachmentCommand());
addCommand(new GetUserStatusCommand());
addCommand(new JoinGroupCommand());
addCommand(new JsonRpcDispatcherCommand());

View file

@ -26,27 +26,20 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.addArgument("--id")
.required(true)
.help("The ID of the attachment file.");
var mut = subparser.addMutuallyExclusiveGroup()
.required(true);
mut.addArgument("--recipient")
.help("Sender of the attachment");
mut.addArgument("-g", "--group-id")
.help("Group in which the attachment was received");
subparser.addArgument("--id").required(true).help("The ID of the attachment file.");
var mut = subparser.addMutuallyExclusiveGroup().required(true);
mut.addArgument("--recipient").help("Sender of the attachment");
mut.addArgument("-g", "--group-id").help("Group in which the attachment was received");
}
@Override
public void handleCommand(
final Namespace ns,
final Manager m,
final OutputWriter outputWriter
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
final var id = ns.getString("id");
try(InputStream attachment = m.retrieveAttachment(id)) {
try (InputStream attachment = m.retrieveAttachment(id)) {
if (outputWriter instanceof PlainTextWriter writer) {
final var bytes = attachment.readAllBytes();
final var base64 = Base64.getEncoder().encodeToString(bytes);