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
.NotPrimaryDeviceException
;
11 import org
.asamk
.signal
.output
.OutputWriter
;
13 import java
.io
.IOException
;
15 public class RemoveDeviceCommand
implements JsonRpcLocalCommand
{
18 public String
getName() {
19 return "removeDevice";
23 public void attachToSubparser(final Subparser subparser
) {
24 subparser
.help("Remove a linked device.");
25 subparser
.addArgument("-d", "--device-id", "--deviceId")
28 .help("Specify the device you want to remove. Use listDevices to see the deviceIds.");
32 public void handleCommand(
35 final OutputWriter outputWriter
36 ) throws CommandException
{
38 final var deviceId
= ns
.getInt("device-id");
39 m
.removeLinkedDevices(deviceId
);
40 } catch (NotPrimaryDeviceException e
) {
41 throw new UserErrorException("This command doesn't work on linked devices.");
42 } catch (IOException e
) {
43 throw new IOErrorException("Error while removing device: " + e
.getMessage(), e
);