-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.go
41 lines (37 loc) · 1 KB
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package inputs
import (
"bufio"
"fmt"
"os"
"os/user"
"strings"
"github.com/hexbotio/hex/models"
"github.com/hexbotio/hex/parse"
)
// Cli struct
type Cli struct {
}
// Read function
func (x Cli) Read(inputMsgs chan<- models.Message, config models.Config) {
hostname, _ := os.Hostname()
user, _ := user.Current()
fmt.Print("Starting in cli mode...\n")
fmt.Print("\n", config.BotName, "> ")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
req := scanner.Text()
fmt.Print("\n", config.BotName, "> ")
input, debug := parse.Flag(req, "--debug")
if strings.TrimSpace(input) != "" {
message := models.NewMessage()
message.Attributes["hex.service"] = "cli"
message.Attributes["hex.hostname"] = hostname
message.Attributes["hex.user"] = user.Username
message.Attributes["hex.input"] = input
message.Debug = debug
config.Logger.Debug("Cli Input - ID:" + message.Attributes["hex.id"])
config.Logger.Trace(fmt.Sprintf("Message: %+v", message))
inputMsgs <- message
}
}
}