]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/AddDeviceCommand.java
Ensure uniqueness of dbus identity names
[signal-cli] / src / main / java / org / asamk / signal / commands / AddDeviceCommand.java
index 24c4ea9127b6d239c17eb4beb005d7be33cb2c24..47cf87485c32a3bec5fc27c1ff1ea5419f60268e 100644 (file)
@@ -7,7 +7,9 @@ import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
 import org.asamk.signal.manager.Manager;
+import org.asamk.signal.manager.api.DeviceLinkUrl;
 import org.asamk.signal.manager.api.InvalidDeviceLinkException;
+import org.asamk.signal.manager.api.NotPrimaryDeviceException;
 import org.asamk.signal.output.OutputWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -27,7 +29,7 @@ public class AddDeviceCommand implements JsonRpcLocalCommand {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
-        subparser.help("Link another device to this device. Only works, if this is the master device.");
+        subparser.help("Link another device to this device. Only works, if this is the primary device.");
         subparser.addArgument("--uri")
                 .required(true)
                 .help("Specify the uri contained in the QR code shown by the new device.");
@@ -45,13 +47,16 @@ public class AddDeviceCommand implements JsonRpcLocalCommand {
         }
 
         try {
-            m.addDeviceLink(linkUri);
+            var deviceLinkUrl = DeviceLinkUrl.parseDeviceLinkUri(linkUri);
+            m.addDeviceLink(deviceLinkUrl);
         } catch (IOException e) {
-            logger.error("Add device link failed", e);
+            logger.error("Add device link failed: {}", e.getMessage());
             throw new IOErrorException("Add device link failed", e);
         } catch (InvalidDeviceLinkException e) {
-            logger.error("Add device link failed", e);
-            throw new UserErrorException("Add device link failed.", e);
+            logger.error("Invalid device link");
+            throw new UserErrorException("Invalid device link", e);
+        } catch (NotPrimaryDeviceException e) {
+            throw new UserErrorException("This command doesn't work on linked devices.");
         }
     }
 }