mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 11:00:38 +00:00
Split commands into separate classes
This commit is contained in:
parent
2ab70edc68
commit
f60a10eb6e
30 changed files with 1121 additions and 742 deletions
50
src/main/java/org/asamk/signal/commands/LinkCommand.java
Normal file
50
src/main/java/org/asamk/signal/commands/LinkCommand.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
import org.asamk.signal.UserAlreadyExists;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||
|
||||
public class LinkCommand implements LocalCommand {
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.addArgument("-n", "--name")
|
||||
.help("Specify a name to describe this new device.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
String deviceName = ns.getString("name");
|
||||
if (deviceName == null) {
|
||||
deviceName = "cli";
|
||||
}
|
||||
try {
|
||||
System.out.println(m.getDeviceLinkUri());
|
||||
m.finishDeviceLink(deviceName);
|
||||
System.out.println("Associated with: " + m.getUsername());
|
||||
} catch (TimeoutException e) {
|
||||
System.err.println("Link request timed out, please try again.");
|
||||
return 3;
|
||||
} catch (IOException e) {
|
||||
System.err.println("Link request error: " + e.getMessage());
|
||||
return 3;
|
||||
} catch (AssertionError e) {
|
||||
handleAssertionError(e);
|
||||
return 1;
|
||||
} catch (InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
return 2;
|
||||
} catch (UserAlreadyExists e) {
|
||||
System.err.println("The user " + e.getUsername() + " already exists\nDelete \"" + e.getFileName() + "\" before trying again.");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue