- DBusConnection.DBusBusType busType;
- if (systemBus) {
- busType = DBusConnection.DBusBusType.SYSTEM;
- } else {
- busType = DBusConnection.DBusBusType.SESSION;
- }
- try (var dBusConn = DBusConnection.getConnection(busType)) {
- if (command instanceof ProvisioningCommand c) {
- if (account != null) {
- throw new UserErrorException("You cannot specify a account (phone number) when linking");
- }
-
- handleProvisioningCommand(c, dBusConn, outputWriter);
- return;
- }
-
- if (account == null && command instanceof MultiLocalCommand c) {
- handleMultiLocalCommand(c, dBusConn, outputWriter);
- return;
- }
- if (account != null && command instanceof RegistrationCommand c) {
- handleRegistrationCommand(c, account, dBusConn, outputWriter);
- return;
- }
- if (!(command instanceof LocalCommand localCommand)) {
- throw new UserErrorException("Command only works in multi-account mode");
- }
-
- var accountObjectPath = account == null ? tryGetSingleAccountObjectPath(dBusConn) : null;
- if (accountObjectPath == null) {
- accountObjectPath = DbusConfig.getObjectPath(account);
- }
- handleLocalCommand(localCommand, accountObjectPath, dBusConn, outputWriter);
+ final var busType = systemBus ? DBusConnection.DBusBusType.SYSTEM : DBusConnection.DBusBusType.SESSION;
+ try (var dBusConn = DBusConnectionBuilder.forType(busType).build()) {
+ DbusCommandHandler.handleCommand(command, account, dBusConn, commandHandler);