-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.go
67 lines (53 loc) · 1.33 KB
/
control.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
//
//// IMPORTS
//
import (
// Modules in GOROOT
"fmt"
"os"
// External modules
)
//
//// FINISH/RESPONSE/STATE CONTROL
//
func finishProgram(code int) {
os.Exit(code)
}
type functionResponse struct {
exitCode int
message string
logLevel string
indentLevel int
}
func incrementProgramIndentLevel(program Program, count int) Program {
program.indentLevel = program.indentLevel + 1
return program
}
func decrementProgramIndentLevel(program Program, count int) Program {
program.indentLevel = program.indentLevel - 1
return program
}
func handleFunctionResponse(response functionResponse, finishProgramAfter bool) {
if response.exitCode != 0 {
if response.logLevel == "attention" {
showAttention(fmt.Sprintf("> "+response.message), response.indentLevel)
if finishProgramAfter == true {
space()
finishProgram(response.exitCode)
}
} else if response.logLevel == "error" {
showError(fmt.Sprintf("> Error: "+response.message), response.indentLevel)
if finishProgramAfter == true {
space()
finishProgram(response.exitCode)
}
}
} else {
if response.logLevel == "attention" {
showAttention(fmt.Sprintf("> "+response.message), response.indentLevel)
} else if response.logLevel == "success" {
showSuccess(fmt.Sprintf("> "+response.message), response.indentLevel)
}
}
}