[agent-wdd] 小小新增部分内容
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var CommonDiskPath = []string{
|
||||
@@ -81,8 +82,8 @@ func DiskListGather() {
|
||||
}
|
||||
|
||||
func (disk *Disk) calculateDiskUsage() {
|
||||
var stat unix.Statfs_t
|
||||
err := unix.Statfs(disk.Path, &stat)
|
||||
var stat syscall.Statfs_t
|
||||
err := syscall.Statfs(disk.Path, &stat)
|
||||
if err != nil {
|
||||
log.Error("disk syscall error: %v", err)
|
||||
disk.Size = "0B"
|
||||
|
||||
@@ -16,11 +16,11 @@ try {
|
||||
Write-Host "4. Exec the command ..." -ForegroundColor Blue
|
||||
Write-Host ""
|
||||
Write-Host ""
|
||||
ssh root@192.168.35.71 "chmod +x agent-wdd_linux_amd64 && ./agent-wdd_linux_amd64 info disk"
|
||||
ssh root@192.168.35.71 "chmod +x agent-wdd_linux_amd64 && ./agent-wdd_linux_amd64 download http://192.168.35.70:9000/ping/ 123.txt"
|
||||
Write-Host ""
|
||||
Write-Host ""
|
||||
Write-Host "5. Cheak Info Result ..." -ForegroundColor Blue
|
||||
ssh root@192.168.35.71 "cat /usr/local/etc/wdd/agent-wdd-config.yaml"
|
||||
# Write-Host "5. Cheak Info Result ..." -ForegroundColor Blue
|
||||
# ssh root@192.168.35.71 "cat /usr/local/etc/wdd/agent-wdd-config.yaml"
|
||||
|
||||
} catch {
|
||||
Write-Host "操作失败: $_" -ForegroundColor Red
|
||||
|
||||
@@ -47,7 +47,7 @@ func downloadWithProgress(client *http.Client, url, dest string) (bool, string)
|
||||
var downloaded int64
|
||||
|
||||
// 打印下载信息
|
||||
fmt.Printf("开始下载文件: %s 文件大小: %s\n", url, HumanSizeInt(size))
|
||||
fmt.Printf("开始下载: %s 大小: %s\n", url, HumanSizeInt(size))
|
||||
|
||||
// 创建带进度跟踪的Reader
|
||||
progressReader := &progressReader{
|
||||
|
||||
Reference in New Issue
Block a user