-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (35 loc) · 856 Bytes
/
main.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
42
package main
import (
"bufio"
"fmt"
"github.com/amitbasuri/linuxPathTraversal/system"
"os"
"strings"
)
const sessionClearInput = "session clear"
func main() {
fmt.Println("Starting your application...")
state := system.NewState()
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input := scanner.Text()
input = strings.TrimSpace(input)
if input == sessionClearInput {
state = system.NewState() // flush the state
continue
}
msg := executeInput(input, state)
fmt.Println(msg)
}
if scanner.Err() != nil {
fmt.Println(scanner.Err())
}
}
// executeInput executes the Input to the system current state
func executeInput(input string, state *system.State) string {
cmd, err := system.NewCmdFromStr(input)
if err != nil {
return fmt.Sprintf("%s", err)
}
return system.ExecuteCommandInCurrState(cmd, state)
}