]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/AddDeviceCommand.java
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
.UnexpectedErrorException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
10 import org
.asamk
.signal
.manager
.Manager
;
11 import org
.slf4j
.Logger
;
12 import org
.slf4j
.LoggerFactory
;
13 import org
.whispersystems
.libsignal
.InvalidKeyException
;
15 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
19 public class AddDeviceCommand
implements LocalCommand
{
21 private final static Logger logger
= LoggerFactory
.getLogger(AddDeviceCommand
.class);
24 public 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.");
32 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
34 m
.addDeviceLink(new URI(ns
.getString("uri")));
35 } catch (IOException e
) {
36 logger
.error("Add device link failed", e
);
37 throw new IOErrorException("Add device link failed");
38 } catch (URISyntaxException e
) {
39 throw new UserErrorException("Device link uri has invalid format: {}" + e
.getMessage());
40 } catch (InvalidKeyException e
) {
41 logger
.error("Add device link failed", e
);
42 throw new UnexpectedErrorException("Add device link failed.");