+ private OutputWriter getOutputWriter(final Command command) throws UserErrorException {
+ final var outputTypeInput = ns.<OutputType>get("output");
+ final var outputType = outputTypeInput == null ? command.getSupportedOutputTypes()
+ .stream()
+ .findFirst()
+ .orElse(null) : outputTypeInput;
+ final var writer = new BufferedWriter(new OutputStreamWriter(System.out, IOUtils.getConsoleCharset()));
+ final var outputWriter = outputType == null
+ ? null
+ : outputType == OutputType.JSON ? new JsonWriterImpl(writer) : new PlainTextWriterImpl(writer);
+
+ if (outputWriter != null && !command.getSupportedOutputTypes().contains(outputType)) {
+ throw new UserErrorException("Command doesn't support output type " + outputType);
+ }
+ return outputWriter;
+ }
+
+ private SignalAccountFiles loadSignalAccountFiles() throws IOErrorException {
+ final File configPath;
+ final var config = ns.getString("config");
+ if (config != null) {
+ configPath = new File(config);
+ } else {
+ configPath = getDefaultConfigPath();
+ }
+
+ final var serviceEnvironmentCli = ns.<ServiceEnvironmentCli>get("service-environment");
+ final var serviceEnvironment = serviceEnvironmentCli == ServiceEnvironmentCli.LIVE
+ ? ServiceEnvironment.LIVE
+ : ServiceEnvironment.STAGING;
+
+ final var trustNewIdentityCli = ns.<TrustNewIdentityCli>get("trust-new-identities");
+ final var trustNewIdentity = trustNewIdentityCli == TrustNewIdentityCli.ON_FIRST_USE
+ ? TrustNewIdentity.ON_FIRST_USE
+ : trustNewIdentityCli == TrustNewIdentityCli.ALWAYS ? TrustNewIdentity.ALWAYS : TrustNewIdentity.NEVER;
+
+ final var disableSendLog = Boolean.TRUE.equals(ns.getBoolean("disable-send-log"));
+
+ try {
+ return new SignalAccountFiles(configPath,
+ serviceEnvironment,
+ BaseConfig.USER_AGENT,
+ new Settings(trustNewIdentity, disableSendLog));
+ } catch (IOException e) {
+ throw new IOErrorException("Failed to read local accounts list", e);
+ }