Skip to content

Commit 27e92df

Browse files
committed
✨ Feat: Add command line interface.
- Add commons-cli dependency to build.gradle.kts - Implement basic command line interface in Main.kt- Add help option to display usage information - Add serve option to start the server
1 parent 0743461 commit 27e92df

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

fifu-server-backup/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies {
1010
implementation("io.vertx:vertx-web:4.5.9")
1111
implementation("dev.samstevens.totp:totp:1.7.1")
1212
implementation("commons-net:commons-net:3.9.0")
13+
implementation("commons-cli:commons-cli:1.9.0")
1314
}
1415

1516
tasks.withType<Jar> {
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
package `fun`.fifu.serverbackup
22

3+
import org.apache.commons.cli.*
4+
35
class Main {
46
companion object {
57
@JvmStatic
68
fun main(args: Array<String>) {
7-
DataServer.startHTTPServer(6542, -1)
8-
println("有没有一种可能,这只是一只普通的Minecraft插件捏qwq")
9+
val options = Options()
10+
11+
val helpOption = Option("h", "help", false, "显示帮助信息")
12+
val serveOption = Option("s", "serve", false, "启动服务")
13+
14+
options.addOption(helpOption)
15+
options.addOption(serveOption)
16+
17+
val formatter = HelpFormatter()
18+
19+
val parser: CommandLineParser = DefaultParser()
20+
val cmd = parser.parse(options, args)
21+
22+
if (args.isEmpty() || cmd.hasOption(helpOption)) {
23+
formatter.printHelp("有没有一种可能,这只是一只普通的Minecraft插件捏qwq", options)
24+
return
25+
}
26+
27+
if (cmd.hasOption(serveOption)) {
28+
DataServer.startHTTPServer(6542, -1)
29+
return
30+
}
31+
932
}
1033
}
1134
}

0 commit comments

Comments
 (0)