From d54ebfc7b05ecbbe44728f1030b532fb2f8a4cf0 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Wed, 17 Apr 2024 11:50:13 +0800 Subject: [PATCH] [agent] - bastion mode init --- agent-go/a_init/BastionInitializaion.go | 8 +++----- agent-go/a_init/bastion_init/config.go | 26 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 agent-go/a_init/bastion_init/config.go diff --git a/agent-go/a_init/BastionInitializaion.go b/agent-go/a_init/BastionInitializaion.go index d40ca91..2bb98ef 100644 --- a/agent-go/a_init/BastionInitializaion.go +++ b/agent-go/a_init/BastionInitializaion.go @@ -6,6 +6,7 @@ import ( "os" "strings" "wdd.io/agent-go/a_agent" + "wdd.io/agent-go/a_init/bastion_init" ) /* @@ -74,17 +75,14 @@ func BastionModeInit() { reader := bufio.NewReader(os.Stdin) for { - fmt.Print("> ") + fmt.Print("enter ==> ") text, _ := reader.ReadString('\n') text = strings.TrimSpace(text) if text == "quit" { break } else if text == "help" { - fmt.Println("Available commands:") - fmt.Println("- help: show this help message") - fmt.Println("- quit: exit the program") - fmt.Println("- [command name]: execute a command") + bastion_init.PrintBastionHelp() } else { // Execute the command fmt.Println("Executing command:", text) diff --git a/agent-go/a_init/bastion_init/config.go b/agent-go/a_init/bastion_init/config.go new file mode 100644 index 0000000..fed3570 --- /dev/null +++ b/agent-go/a_init/bastion_init/config.go @@ -0,0 +1,26 @@ +package bastion_init + +import ( + "fmt" + "io" + "os" +) + +// getStandardOutPutLength 获取到标准输出终端的长度 +func getStandardOutPutLength() (int, error) { + buffer := make([]byte, 0) + _, err := io.ReadFull(os.Stdout, buffer) + if err != nil { + return 0, err + } + return len(buffer), nil +} + +func PrintBastionHelp() { + length, err := getStandardOutPutLength() + if err == nil { + fmt.Printf("标准输出终端的长度: %d 字节\n", length) + } else { + fmt.Println("获取标准输出终端长度时发生错误:", err) + } +}