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
.InvalidDeviceLinkException
;
11 import org
.asamk
.signal
.output
.OutputWriter
;
12 import org
.slf4j
.Logger
;
13 import org
.slf4j
.LoggerFactory
;
15 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
19 public class AddDeviceCommand
implements JsonRpcLocalCommand
{
21 private final static Logger logger
= LoggerFactory
.getLogger(AddDeviceCommand
.class);
24 public String
getName() {
29 public void attachToSubparser(final Subparser subparser
) {
30 subparser
.help("Link another device to this device. Only works, if this is the primary device.");
31 subparser
.addArgument("--uri")
33 .help("Specify the uri contained in the QR code shown by the new device.");
37 public void handleCommand(
38 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
39 ) throws CommandException
{
42 linkUri
= new URI(ns
.getString("uri"));
43 } catch (URISyntaxException e
) {
44 throw new UserErrorException("Device link uri has invalid format: " + e
.getMessage());
48 m
.addDeviceLink(linkUri
);
49 } catch (IOException e
) {
50 logger
.error("Add device link failed", e
);
51 throw new IOErrorException("Add device link failed", e
);
52 } catch (InvalidDeviceLinkException e
) {
53 logger
.error("Add device link failed", e
);
54 throw new UserErrorException("Add device link failed.", e
);