[agent] - bastion mode init

This commit is contained in:
zeaslity
2024-04-17 11:50:13 +08:00
parent f20d5e549c
commit d54ebfc7b0
2 changed files with 29 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ import (
"os" "os"
"strings" "strings"
"wdd.io/agent-go/a_agent" "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) reader := bufio.NewReader(os.Stdin)
for { for {
fmt.Print("> ") fmt.Print("enter ==> ")
text, _ := reader.ReadString('\n') text, _ := reader.ReadString('\n')
text = strings.TrimSpace(text) text = strings.TrimSpace(text)
if text == "quit" { if text == "quit" {
break break
} else if text == "help" { } else if text == "help" {
fmt.Println("Available commands:") bastion_init.PrintBastionHelp()
fmt.Println("- help: show this help message")
fmt.Println("- quit: exit the program")
fmt.Println("- [command name]: execute a command")
} else { } else {
// Execute the command // Execute the command
fmt.Println("Executing command:", text) fmt.Println("Executing command:", text)

View File

@@ -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)
}
}