[agent] - bastion mode init
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
26
agent-go/a_init/bastion_init/config.go
Normal file
26
agent-go/a_init/bastion_init/config.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user