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
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.manager
.api
.DeviceLinkUrl
;
11 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
12 import org
.asamk
.signal
.output
.OutputWriter
;
13 import org
.slf4j
.Logger
;
14 import org
.slf4j
.LoggerFactory
;
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 primary 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
{
43 linkUri
= new URI(ns
.getString("uri"));
44 } catch (URISyntaxException e
) {
45 throw new UserErrorException("Device link uri has invalid format: " + e
.getMessage());
49 var deviceLinkUrl
= DeviceLinkUrl
.parseDeviceLinkUri(linkUri
);
50 m
.addDeviceLink(deviceLinkUrl
);
51 } catch (IOException e
) {
52 logger
.error("Add device link failed", e
);
53 throw new IOErrorException("Add device link failed", e
);
54 } catch (InvalidDeviceLinkException e
) {
55 logger
.error("Add device link failed", e
);
56 throw new UserErrorException("Add device link failed.", e
);