[agent][wdd] - 初始化项目

This commit is contained in:
zeaslity
2025-02-10 15:07:44 +08:00
parent a0811d62e7
commit b8f0b14852
12 changed files with 455 additions and 0 deletions

29
agent-wdd/cmd/Acme.go Normal file
View File

@@ -0,0 +1,29 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// addAcmeSubcommands acme的相关任务
func addAcmeSubcommands(cmd *cobra.Command) {
proxyCmd := &cobra.Command{
Use: "proxy [url] [dest]",
Short: "使用代理下载",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Downloading with proxy: %s -> %s\n", args[0], args[1])
},
}
unproxyCmd := &cobra.Command{
Use: "unproxy [url] [dest]",
Short: "不使用代理下载",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Downloading without proxy: %s -> %s\n", args[0], args[1])
},
}
cmd.AddCommand(proxyCmd, unproxyCmd)
}

73
agent-wdd/cmd/Base.go Normal file
View File

@@ -0,0 +1,73 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// 添加base子命令
func addBaseSubcommands(cmd *cobra.Command) {
// 1.1 docker
dockerCmd := &cobra.Command{
Use: "docker",
Short: "Docker相关操作",
}
addDockerSubcommands(dockerCmd)
// 1.2 dockercompose
dockerComposeCmd := &cobra.Command{
Use: "dockercompose",
Short: "Docker Compose相关操作",
}
addDockerComposeSubcommands(dockerComposeCmd)
// 其他base子命令...
cmd.AddCommand(
dockerCmd,
dockerComposeCmd,
// 其他命令...
)
}
// 添加docker子命令
func addDockerSubcommands(cmd *cobra.Command) {
onlineCmd := &cobra.Command{
Use: "online [version]",
Short: "网络安装Docker",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Installing Docker version: %s\n", args[0])
},
}
removeCmd := &cobra.Command{
Use: "remove",
Short: "卸载Docker",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Removing Docker...")
},
}
localCmd := &cobra.Command{
Use: "local [path]",
Short: "本地安装Docker",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Installing Docker from: %s\n", args[0])
},
}
cmd.AddCommand(onlineCmd, removeCmd, localCmd)
}
func addDockerComposeSubcommands(cmd *cobra.Command) {
}
// addToolsSubcommands 利用本机的yumapt等从网络安装常用的软件
func addToolsSubcommands(cmd *cobra.Command) {
// 检测本机使用的包安装方式为apt还是yum
// 检查本机
//
}

7
agent-wdd/cmd/Config.go Normal file
View File

@@ -0,0 +1,7 @@
package cmd
import "github.com/spf13/cobra"
func addConfigSubcommands(cmd *cobra.Command) {
}

31
agent-wdd/cmd/Download.go Normal file
View File

@@ -0,0 +1,31 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// 示例添加download子命令
func addDownloadSubcommands(cmd *cobra.Command) {
proxyCmd := &cobra.Command{
Use: "proxy [url] [dest]",
Short: "使用代理下载",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Downloading with proxy: %s -> %s\n", args[0], args[1])
},
}
unproxyCmd := &cobra.Command{
Use: "unproxy [url] [dest]",
Short: "不使用代理下载",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Downloading without proxy: %s -> %s\n", args[0], args[1])
},
}
cmd.AddCommand(proxyCmd, unproxyCmd)
}
// 根据需求补充其他子命令的添加函数...

38
agent-wdd/cmd/Proxy.go Normal file
View File

@@ -0,0 +1,38 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// 添加proxy子命令
func addProxySubcommands(cmd *cobra.Command) {
xrayCmd := &cobra.Command{
Use: "xray",
Short: "Xray相关操作",
}
xrayCmd.AddCommand(
&cobra.Command{
Use: "install",
Short: "安装Xray",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Installing Xray...")
},
},
// 其他xray子命令...
)
cmd.AddCommand(
xrayCmd,
&cobra.Command{
Use: "vmess",
Short: "设置VMESS代理",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Setting up VMESS proxy...")
},
},
// 其他proxy子命令...
)
}
// 其他命令结构类似,根据需求补充完整...

7
agent-wdd/cmd/WddHost.go Normal file
View File

@@ -0,0 +1,7 @@
package cmd
import "github.com/spf13/cobra"
func addWddSubcommands(cmd *cobra.Command) {
}

7
agent-wdd/cmd/Zsh.go Normal file
View File

@@ -0,0 +1,7 @@
package cmd
import "github.com/spf13/cobra"
func addZshSubcommands(cmd *cobra.Command) {
}

View File

@@ -58,6 +58,97 @@ func initConfig() {
func Execute() {
// 1. base命令
baseCmd := &cobra.Command{
Use: "base",
Short: "服务器基础操作",
}
addBaseSubcommands(baseCmd)
// 2. zsh命令
zshCmd := &cobra.Command{
Use: "zsh",
Short: "zsh相关的内容",
}
addZshSubcommands(zshCmd)
// 3. proxy命令
proxyCmd := &cobra.Command{
Use: "proxy",
Short: "主机代理相关的内容",
}
addProxySubcommands(proxyCmd)
// 4. acme命令
acmeCmd := &cobra.Command{
Use: "acme",
Short: "acme相关的内容",
}
addAcmeSubcommands(acmeCmd)
// 5. wdd命令
wddCmd := &cobra.Command{
Use: "wdd",
Short: "WDD相关操作",
}
addWddSubcommands(wddCmd)
// 6. security命令
securityCmd := &cobra.Command{
Use: "security",
Short: "安全相关操作",
}
// 7. info命令
infoCmd := &cobra.Command{
Use: "info",
Short: "打印主机详细信息",
Run: func(cmd *cobra.Command, args []string) {
// 实现info逻辑
},
}
// 8. version命令
versionCmd := &cobra.Command{
Use: "version",
Short: "打印版本信息",
Run: func(cmd *cobra.Command, args []string) {
// 实现version逻辑
},
}
// 9. config命令
configCmd := &cobra.Command{
Use: "config",
Short: "配置文件管理",
}
addConfigSubcommands(configCmd)
// 10. download命令
downloadCmd := &cobra.Command{
Use: "download",
Short: "文件下载管理",
}
addDownloadSubcommands(downloadCmd)
// 添加所有根命令
rootCmd.AddCommand(
baseCmd,
zshCmd,
proxyCmd,
acmeCmd,
wddCmd,
securityCmd,
infoCmd,
versionCmd,
configCmd,
downloadCmd,
)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
}
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)