]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/App.java
Fix inspections
[signal-cli] / src / main / java / org / asamk / signal / App.java
index fdd88e7c47282a7a8c82d9bd4fea413c54a57940..f0ebbfaea48012573625ed4f639b5e6c2989bb8b 100644 (file)
@@ -165,20 +165,7 @@ public class App {
                 return;
             }
 
-            Set<String> 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.");
         }
@@ -190,11 +177,27 @@ public class App {
 
         if (command instanceof LocalCommand localCommand) {
             handleLocalCommand(localCommand, account, signalAccountFiles, commandHandler);
+            return;
         }
 
         throw new UserErrorException("Command only works in multi-account mode");
     }
 
+    private static String getAccountIfOnlyOne(final SignalAccountFiles signalAccountFiles) throws IOErrorException, UserErrorException {
+        Set<String> 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.<OutputType>get("output");
         final var outputType = outputTypeInput == null ? command.getSupportedOutputTypes()
@@ -273,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);
         }
     }