use jOptSimple
This commit is contained in:
@@ -17,7 +17,8 @@ ext {
|
|||||||
reactor : 'io.projectreactor:reactor-core:3.4.5',
|
reactor : 'io.projectreactor:reactor-core:3.4.5',
|
||||||
yaml : 'org.yaml:snakeyaml:1.28',
|
yaml : 'org.yaml:snakeyaml:1.28',
|
||||||
json : 'com.eclipsesource.minimal-json:minimal-json:0.9.5',
|
json : 'com.eclipsesource.minimal-json:minimal-json:0.9.5',
|
||||||
ioutils : 'commons-io:commons-io:2.6'
|
ioutils : 'commons-io:commons-io:2.6',
|
||||||
|
jopt : 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3'
|
||||||
]
|
]
|
||||||
|
|
||||||
libs.logger = [
|
libs.logger = [
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ dependencies {
|
|||||||
implementation libs.guava
|
implementation libs.guava
|
||||||
implementation libs.yaml
|
implementation libs.yaml
|
||||||
implementation libs.ioutils
|
implementation libs.ioutils
|
||||||
|
implementation libs.jopt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package mc.server;
|
package mc.server;
|
||||||
|
|
||||||
|
import joptsimple.OptionParser;
|
||||||
|
import joptsimple.OptionSet;
|
||||||
|
import joptsimple.util.PathConverter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.protocol.NettyServer;
|
import mc.protocol.NettyServer;
|
||||||
import mc.protocol.ProtocolConstant;
|
import mc.protocol.ProtocolConstant;
|
||||||
@@ -23,19 +26,15 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
private void run(OptionSet optionSet) {
|
||||||
log.info("mc-project launch");
|
log.info("mc-project launch");
|
||||||
|
|
||||||
ConfigModule configModule;
|
ConfigModule configModule = new ConfigModule((Path) optionSet.valueOf("config"));
|
||||||
if (args.length > 0) {
|
|
||||||
configModule = new ConfigModule(Paths.get(args[0]));
|
|
||||||
} else {
|
|
||||||
configModule = new ConfigModule(Paths.get("config.yml"));
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerComponent serverComponent = DaggerServerComponent.builder()
|
ServerComponent serverComponent = DaggerServerComponent.builder()
|
||||||
.configModule(configModule)
|
.configModule(configModule)
|
||||||
@@ -86,6 +85,42 @@ public class Main {
|
|||||||
server.bind(config.server().host(), config.server().port());
|
server.bind(config.server().host(), config.server().port());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("java:S106")
|
||||||
|
public static void main(String[] args) {
|
||||||
|
OptionParser optionParser = createOptionParser();
|
||||||
|
OptionSet optionSet = optionParser.parse(args);
|
||||||
|
|
||||||
|
if (optionSet.has("help")) {
|
||||||
|
try {
|
||||||
|
optionParser.printHelpOn(System.out);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.printf("Can't print help page: %s%n", e.getMessage());
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
optionSet.asMap().forEach((optionSpec, objects) -> {
|
||||||
|
if (optionSpec.isForHelp()) return;
|
||||||
|
log.debug("OptionSet | {} = {}", optionSpec.options(), objects);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
new Main().run(optionSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OptionParser createOptionParser() {
|
||||||
|
OptionParser optionParser = new OptionParser();
|
||||||
|
optionParser.acceptsAll(List.of("h", "help"), "Help page").forHelp();
|
||||||
|
optionParser.accepts("config", "Path to configuration file")
|
||||||
|
.withRequiredArg()
|
||||||
|
.withValuesConvertedBy(new PathConverter())
|
||||||
|
.defaultsTo(Paths.get("config.yml"));
|
||||||
|
|
||||||
|
return optionParser;
|
||||||
|
}
|
||||||
|
|
||||||
private static String faviconToBase64(Path iconPath) {
|
private static String faviconToBase64(Path iconPath) {
|
||||||
try {
|
try {
|
||||||
return "data:image/png;base64," +
|
return "data:image/png;base64," +
|
||||||
|
|||||||
Reference in New Issue
Block a user