Skip to content

Commit

Permalink
feat 使用spring-shell 最新用法
Browse files Browse the repository at this point in the history
  • Loading branch information
wertycn committed Feb 4, 2024
1 parent 7b3da4c commit d82076b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<version>3.10.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.modulith</groupId>-->
<!-- <artifactId>spring-modulith-starter-core</artifactId>-->
Expand Down
7 changes: 7 additions & 0 deletions spring-shell.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1707063293854:你好
1707063298440:gen
1707063304922:ls
1707063306664:help
1707063408183:generate help
1707063432086:generate --struct_file_path ./
1707063473729:generate --struct_file_path D:\\mycode\\wgnet-register\\wireguard-registry-core\\src\\test\\resources\\wireguard-network-example.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package icu.debug.net.wg.client;

import icu.debug.net.wg.client.command.LightCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.shell.command.annotation.CommandScan;
import org.springframework.shell.command.annotation.EnableCommand;

/**
* @author hanjinxiang@debug.icu
* @date 2024-02-04 1:13
*/
@Slf4j
//@CommandScan
@EnableCommand(LightCommand.class)
@SpringBootApplication
public class Application {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package icu.debug.net.wg.client.command;

import icu.debug.net.wg.client.module.ConfigGenerateModule;
import org.springframework.shell.command.annotation.Command;
import org.springframework.shell.context.InteractionMode;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
Expand All @@ -14,7 +16,7 @@
* @author hanjinxiang@debug.icu
* @date 2024-02-04 0:44
*/
@ShellComponent("light")
@Command(interactionMode = InteractionMode.NONINTERACTIVE)
public class LightCommand {

private final ConfigGenerateModule module;
Expand All @@ -23,7 +25,7 @@ public LightCommand(ConfigGenerateModule module) {
this.module = module;
}

@ShellMethod(key = "generate")
@Command(command = "generate", alias = "gen", description = "基于组网规划配置生成组网配置文件", interactionMode = InteractionMode.NONINTERACTIVE)
public String helloWorld(
@ShellOption(value = "struct_file_path", help = "网络规划JSON配置") String structFile,
@ShellOption(value = "output_path", defaultValue = "./", help = "生成结果存储路径") String output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import icu.debug.net.wg.core.model.config.WireGuardIniConfig;
import icu.debug.net.wg.core.model.config.WireGuardNetProperties;
import icu.debug.net.wg.core.model.network.WireGuardNetworkStruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

Expand All @@ -22,13 +23,15 @@
* @author hanjinxiang@debug.icu
* @date 2024-02-04 1:53
*/
@Slf4j
@Component
public class ConfigGenerateModule {

private final WireGuardNetProperties defaultProperties;

public ConfigGenerateModule(WireGuardNetProperties defaultProperties) {
this.defaultProperties = defaultProperties;
log.info("default properties {}", this.defaultProperties);
}

public List<Path> generateFiles(String structFilePath, String outputPath) {
Expand Down Expand Up @@ -80,7 +83,7 @@ private static String readFile(String structFilePath) {
try {
return FileHelper.read(structFilePath);
} catch (IOException e) {
throw new IllegalArgumentException("file: [" + structFilePath + "] struct file load failed:" + e.getMessage(), e);
throw new IllegalArgumentException("file: [" + Paths.get(structFilePath) + "] struct file load failed:" + e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
spring:

wireguard:
default:
address: "10.201.1.1"
Expand All @@ -9,7 +11,7 @@ wireguard:
table: "auto"
mtu: 1500
preUp:
# - "ip rule add ipproto tcp dport 22 table 1234"
# - "ip rule add ipproto tcp dport 22 table 1234"
postUp:
- "echo 'hello wireguard'"
preDown:
Expand Down
11 changes: 10 additions & 1 deletion wireguard-registry-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
</project>

0 comments on commit d82076b

Please sign in to comment.