]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/Main.java
Use var instead of explicit types
[signal-cli] / src / main / java / org / asamk / signal / Main.java
1 /*
2 Copyright (C) 2015-2021 AsamK and contributors
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 package org.asamk.signal;
18
19 import net.sourceforge.argparse4j.ArgumentParsers;
20 import net.sourceforge.argparse4j.impl.Arguments;
21 import net.sourceforge.argparse4j.inf.ArgumentParserException;
22 import net.sourceforge.argparse4j.inf.Namespace;
23
24 import org.asamk.signal.manager.LibSignalLogger;
25 import org.asamk.signal.util.SecurityProvider;
26 import org.bouncycastle.jce.provider.BouncyCastleProvider;
27
28 import java.security.Security;
29
30 public class Main {
31
32 public static void main(String[] args) {
33 installSecurityProviderWorkaround();
34
35 // Configuring the logger needs to happen before any logger is initialized
36 configureLogging(isVerbose(args));
37
38 var parser = App.buildArgumentParser();
39
40 var ns = parser.parseArgsOrFail(args);
41
42 var res = new App(ns).init();
43 System.exit(res);
44 }
45
46 private static void installSecurityProviderWorkaround() {
47 // Register our own security provider
48 Security.insertProviderAt(new SecurityProvider(), 1);
49 Security.addProvider(new BouncyCastleProvider());
50 }
51
52 private static boolean isVerbose(String[] args) {
53 var parser = ArgumentParsers.newFor("signal-cli").build().defaultHelp(false);
54 parser.addArgument("--verbose").action(Arguments.storeTrue());
55
56 Namespace ns;
57 try {
58 ns = parser.parseKnownArgs(args, null);
59 } catch (ArgumentParserException e) {
60 return false;
61 }
62
63 return ns.getBoolean("verbose");
64 }
65
66 private static void configureLogging(final boolean verbose) {
67 if (verbose) {
68 System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
69 System.setProperty("org.slf4j.simpleLogger.showThreadName", "true");
70 System.setProperty("org.slf4j.simpleLogger.showShortLogName", "false");
71 System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
72 System.setProperty("org.slf4j.simpleLogger.dateTimeFormat", "yyyy-MM-dd'T'HH:mm:ss.SSSXX");
73 LibSignalLogger.initLogger();
74 } else {
75 System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
76 System.setProperty("org.slf4j.simpleLogger.showThreadName", "false");
77 System.setProperty("org.slf4j.simpleLogger.showShortLogName", "true");
78 System.setProperty("org.slf4j.simpleLogger.showDateTime", "false");
79 }
80 }
81 }