]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/AddDeviceCommand.java
cf993e6de4b89d7064d790df40210043374200f1
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 import static org
.asamk
.signal
.util
.ErrorUtils
.handleAssertionError
;
21 public class AddDeviceCommand
implements LocalCommand
{
23 private final static Logger logger
= LoggerFactory
.getLogger(AddDeviceCommand
.class);
26 public void attachToSubparser(final Subparser subparser
) {
27 subparser
.addArgument("--uri")
29 .help("Specify the uri contained in the QR code shown by the new device.");
33 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
35 m
.addDeviceLink(new URI(ns
.getString("uri")));
36 } catch (IOException e
) {
37 logger
.error("Add device link failed", e
);
38 throw new IOErrorException("Add device link failed");
39 } catch (URISyntaxException e
) {
40 throw new UserErrorException("Device link uri has invalid format: {}" + e
.getMessage());
41 } catch (InvalidKeyException e
) {
42 logger
.error("Add device link failed", e
);
43 throw new UnexpectedErrorException("Add device link failed.");
44 } catch (AssertionError e
) {
45 handleAssertionError(e
);