X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/da25b2a7637754c0bb708d51561b26deb69c1271..fc2e9bbfaec8dbe6e317b951c0d28fa2e9421347:/src/main/java/org/asamk/signal/App.java diff --git a/src/main/java/org/asamk/signal/App.java b/src/main/java/org/asamk/signal/App.java index 9ac4b190..f0ebbfae 100644 --- a/src/main/java/org/asamk/signal/App.java +++ b/src/main/java/org/asamk/signal/App.java @@ -165,20 +165,7 @@ public class App { return; } - Set accounts; - try { - accounts = signalAccountFiles.getAllLocalAccountNumbers(); - } catch (IOException e) { - throw new IOErrorException("Failed to load local accounts file", e); - } - if (accounts.size() == 0) { - throw new UserErrorException("No local users found, you first need to register or link an account"); - } else if (accounts.size() > 1) { - throw new UserErrorException( - "Multiple users found, you need to specify an account (phone number) with -a"); - } - - account = accounts.stream().findFirst().get(); + account = getAccountIfOnlyOne(signalAccountFiles); } else if (!Manager.isValidNumber(account, null)) { throw new UserErrorException("Invalid account (phone number), make sure you include the country code."); } @@ -196,6 +183,21 @@ public class App { throw new UserErrorException("Command only works in multi-account mode"); } + private static String getAccountIfOnlyOne(final SignalAccountFiles signalAccountFiles) throws IOErrorException, UserErrorException { + Set accounts; + try { + accounts = signalAccountFiles.getAllLocalAccountNumbers(); + } catch (IOException e) { + throw new IOErrorException("Failed to load local accounts file", e); + } + if (accounts.isEmpty()) { + throw new UserErrorException("No local users found, you first need to register or link an account"); + } else if (accounts.size() > 1) { + throw new UserErrorException("Multiple users found, you need to specify an account (phone number) with -a"); + } + return accounts.stream().findFirst().get(); + } + private OutputWriter getOutputWriter(final Command command) throws UserErrorException { final var outputTypeInput = ns.get("output"); final var outputType = outputTypeInput == null ? command.getSupportedOutputTypes() @@ -274,8 +276,6 @@ public class App { ) throws CommandException { try (var m = loadManager(account, signalAccountFiles)) { commandHandler.handleLocalCommand(command, m); - } catch (IOException e) { - logger.warn("Cleanup failed", e); } }