38 lines
603 B
Go
38 lines
603 B
Go
|
|
package cmd
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bufio"
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
"strings"
|
||
|
|
"sync"
|
||
|
|
)
|
||
|
|
|
||
|
|
func Start(wg *sync.WaitGroup, stopChan chan struct{}) {
|
||
|
|
defer wg.Done()
|
||
|
|
|
||
|
|
reader := bufio.NewReader(os.Stdin)
|
||
|
|
for {
|
||
|
|
fmt.Print("> ")
|
||
|
|
input, err := reader.ReadString('\n')
|
||
|
|
if err != nil {
|
||
|
|
_, err := fmt.Fprintf(os.Stderr, "Error while reading input: %v", err)
|
||
|
|
if err != nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
close(stopChan)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
input = strings.TrimSpace(input)
|
||
|
|
switch input {
|
||
|
|
case "stop":
|
||
|
|
fmt.Println("Received stop command.")
|
||
|
|
close(stopChan)
|
||
|
|
return
|
||
|
|
default:
|
||
|
|
fmt.Println("Unknown command:", input)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|