Files
ProjectOctopus/agent-wdd/cmd/Download.go
zeaslity 6de29630b5 123
2025-02-27 14:52:57 +08:00

46 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"agent-wdd/log"
"agent-wdd/utils"
"github.com/spf13/cobra"
)
// 示例添加download子命令
func addDownloadSubcommands(cmd *cobra.Command) {
proxyCmd := &cobra.Command{
Use: "proxy [proxyUrl] [url] [dest]",
Short: "使用代理下载 支持socks5代理 http代理",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
// 判定参数是否正确
log.Info("Downloading using proxy: %s -> from %s to %s\n", args[0], args[1], args[2])
},
}
cmd.Run = func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
log.Error("请输入下载地址")
return
} else if len(args) == 1 {
args = append(args, ".")
}
log.Info("Downloading without proxy: %s -> %s\n", args[0], args[1])
downloadOk, resultLog := utils.DownloadFile(args[0], args[1])
if !downloadOk {
log.Error("下载失败: %s", resultLog)
} else {
log.Info("下载成功: %s", args[1])
}
}
cmd.AddCommand(proxyCmd)
}
// 根据需求补充其他子命令的添加函数...