[agent-wdd] 小小新增部分内容

This commit is contained in:
zeaslity
2025-02-27 17:19:36 +08:00
parent b6cc5abc63
commit c10554c218
7 changed files with 15 additions and 46 deletions

View File

@@ -1,29 +1,10 @@
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)
}

View File

@@ -498,7 +498,7 @@ func addDockerComposeSubcommands(cmd *cobra.Command) {
log.Info("Downloading Docker Compose from: %s", downloadURL)
// 下载 Docker Compose
ok, ccc := op.DownloadFile(downloadURL, "/usr/local/bin/docker-compose")
ok, ccc := utils.DownloadFile(downloadURL, "/usr/local/bin/docker-compose")
if !ok {
log.Error("下载 Docker Compose 失败: %s", ccc)
return

View File

@@ -18,7 +18,7 @@ import (
func addDownloadSubcommands(cmd *cobra.Command) {
proxyCmd := &cobra.Command{
Use: "proxy [proxyUrl] [url] [dest]",
Short: "使用代理下载 支持socks5代理 http代理",
Short: "使用代理下载 socks5://[username]:[password]@ip:port http://[username]:[password]@ip:port",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
proxyURL := args[0]
@@ -50,7 +50,8 @@ func addDownloadSubcommands(cmd *cobra.Command) {
log.Error("请输入下载地址")
return
} else if len(args) == 1 {
args = append(args, ".")
timeString := utils.CurrentTimeString()
args = append(args, "./"+timeString+".txt")
}
log.Info("Downloading without proxy: %s -> %s\n", args[0], args[1])

View File

@@ -8,36 +8,21 @@ import (
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var rootCmd = &cobra.Command{
Use: "wdd",
Short: "wdd应用程序是wdd封装的NB工具",
Long: `使用golang的强大特性加上wdd的高超技术,\n打造一个方便、高效、适用于各种LINUX系统的瑞士军刀工具\n 尽情享用!`,
Long: `使用golang的强大特性加上 WDD 的高超技术打造一个方便、高效、适用于各种LINUX系统的瑞士军刀工具!
尽情享用! 尽情享用! 尽情享用!`,
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
},
}
var cfgFile = ""
var userLicense = ""
var projectBase = ""
func init() {
cobra.OnInitialize(config.InitConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
rootCmd.PersistentFlags().StringVarP(&projectBase, "projectbase", "b", "",
"base project directory eg. github.com/spf13/")
rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "Author name for copyright attribution")
rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "Name of license for the project (can provide `licensetext` in config)")
rootCmd.PersistentFlags().Bool("viper", true, "Use Viper for configuration")
viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))
viper.BindPFlag("projectbase", rootCmd.PersistentFlags().Lookup("projectbase"))
viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))
viper.SetDefault("author", "Esdeath Wang(zeaslity@gamil.com)")
viper.SetDefault("license", "apache")
}
func Execute() {
@@ -110,7 +95,7 @@ func Execute() {
// 10. download命令
downloadCmd := &cobra.Command{
Use: "download",
Short: "文件下载管理",
Short: "文件下载,直接下载 [url] [dest_path]",
}
addDownloadSubcommands(downloadCmd)
@@ -125,6 +110,7 @@ func Execute() {
// c.Usage()
// })
// 自定义实现 打印全部的命令
printAllCommands(cmd.Root(), os.Stdout)
},
}