Skip to content

Commit

Permalink
添加从配置文件设置参数功能
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperIceCN committed Jun 11, 2023
1 parent 49c4c0a commit 528f5c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.powernukkitx</groupId>
<artifactId>PNX-CLI</artifactId>
<version>0.1.4</version>
<version>0.1.5</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/cn/powernukkitx/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ public static void main(String[] args) {
}
}
}
var realArgs = args;
if (ConfigUtils.forceArguments() != null) {
realArgs = ConfigUtils.forceArguments();
}
try {
new CommandLine(new Preprocessor()).parseArgs(args);
new CommandLine(new Preprocessor()).parseArgs(realArgs);
} catch (Exception ignore) {

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/powernukkitx/cli/share/CLIConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public interface CLIConstant {
String version = "0.1.4";
String version = "0.1.5";
List<String> authors = List.of("超神的冰凉");
File userDir = new File(System.getProperty("user.dir"));
File programDir = new File(OSUtils.getProgramDir());
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/cn/powernukkitx/cli/util/ConfigUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.powernukkitx.cli.share.CLIConstant;
import com.sun.management.OperatingSystemMXBean;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.*;
Expand Down Expand Up @@ -156,4 +157,12 @@ public static String[] xxOptions() {
public static @Nullable String apiEndpoint() {
return configMap.get("api-endpoint");
}

public static @NotNull String @Nullable [] forceArguments() {
var arguments = configMap.get("force-arguments");
if (arguments == null || arguments.isBlank()) {
return null;
}
return arguments.trim().split(" ");
}
}

0 comments on commit 528f5c8

Please sign in to comment.