-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
79 lines (67 loc) · 1.57 KB
/
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
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
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"slices"
"github.com/kentlouisetonino/baseshift/src/displays"
"github.com/kentlouisetonino/baseshift/src/errors"
"github.com/kentlouisetonino/baseshift/src/helpers"
"github.com/kentlouisetonino/baseshift/src/services/binary"
"github.com/kentlouisetonino/baseshift/src/services/decimal"
"github.com/kentlouisetonino/baseshift/src/services/hexadecimal"
"github.com/kentlouisetonino/baseshift/src/services/octal"
)
func main() {
validOptions := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
isValidMainOption := false
hasError := false
for {
helpers.Clear()
helpers.AddNewLine()
displays.AppDescription()
helpers.AddNewLine()
if hasError {
errors.InvalidOption()
helpers.AddNewLine()
}
displays.AppOptions()
helpers.AddNewLine()
userInput := helpers.MainOptionInput()
if userInput == 13 {
break
}
isValidMainOption = slices.Contains(validOptions, userInput)
if isValidMainOption {
hasError = false
switch userInput {
case 1:
binary.ConvertToDecimal()
case 2:
binary.ConvertToOctal()
case 3:
binary.ConvertToHexadecimal()
case 4:
decimal.ConvertToBinary()
case 5:
decimal.ConvertToOctal()
case 6:
decimal.ConvertToHexadecimal()
case 7:
octal.ConvertToBinary()
case 8:
octal.ConvertToDecimal()
case 9:
octal.ConvertToHexadecimal()
case 10:
hexadecimal.ConvertToBinary()
case 11:
hexadecimal.ConvertToDecimal()
case 12:
hexadecimal.ConvertToOctal()
default:
hasError = true
}
} else {
hasError = true
}
}
helpers.Clear()
}