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) } // 根据需求补充其他子命令的添加函数...