1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.OutputWriter
;
7 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
8 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UnexpectedErrorException
;
10 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
11 import org
.asamk
.signal
.manager
.Manager
;
12 import org
.slf4j
.Logger
;
13 import org
.slf4j
.LoggerFactory
;
14 import org
.whispersystems
.libsignal
.InvalidKeyException
;
16 import java
.io
.IOException
;
18 import java
.net
.URISyntaxException
;
20 public class AddDeviceCommand
implements JsonRpcLocalCommand
{
22 private final static Logger logger
= LoggerFactory
.getLogger(AddDeviceCommand
.class);
24 public static void attachToSubparser(final Subparser subparser
) {
25 subparser
.help("Link another device to this device. Only works, if this is the master device.");
26 subparser
.addArgument("--uri")
28 .help("Specify the uri contained in the QR code shown by the new device.");
31 public AddDeviceCommand(final OutputWriter outputWriter
) {
35 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
37 m
.addDeviceLink(new URI(ns
.getString("uri")));
38 } catch (IOException e
) {
39 logger
.error("Add device link failed", e
);
40 throw new IOErrorException("Add device link failed");
41 } catch (URISyntaxException e
) {
42 throw new UserErrorException("Device link uri has invalid format: " + e
.getMessage());
43 } catch (InvalidKeyException e
) {
44 logger
.error("Add device link failed", e
);
45 throw new UnexpectedErrorException("Add device link failed.");