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);
25 public String
getName() {
30 public void attachToSubparser(final Subparser subparser
) {
31 subparser
.help("Link another device to this device. Only works, if this is the master device.");
32 subparser
.addArgument("--uri")
34 .help("Specify the uri contained in the QR code shown by the new device.");
38 public void handleCommand(
39 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
40 ) throws CommandException
{
42 m
.addDeviceLink(new URI(ns
.getString("uri")));
43 } catch (IOException e
) {
44 logger
.error("Add device link failed", e
);
45 throw new IOErrorException("Add device link failed");
46 } catch (URISyntaxException e
) {
47 throw new UserErrorException("Device link uri has invalid format: " + e
.getMessage());
48 } catch (InvalidKeyException e
) {
49 logger
.error("Add device link failed", e
);
50 throw new UnexpectedErrorException("Add device link failed.");