-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (65 loc) · 1.75 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
package main
import (
"fmt"
"gpm/internal"
"gpm/requests"
"log"
"os"
"strconv"
)
const (
INSTALL = "i"
INSTALL_SEARCH = "is"
SEARCH_CAPACITY = "c"
)
func main() {
var COMMANDS_ARRAY = []string{INSTALL, INSTALL_SEARCH, SEARCH_CAPACITY}
args := os.Args[1:]
recivedArgument, err := internal.ArgumentsFormatter(args, COMMANDS_ARRAY)
if err != nil {
fmt.Println(err)
return
}
for _, commandStruct := range recivedArgument {
switch commandStruct.Commad {
case INSTALL:
pkgNames := requests.ParseHttpString(commandStruct.Value, 1)
result := pkgNames[0]
pkgName, description := result.PkgName, result.PkgDescription
isConfirmed, err := internal.ConsoleOutput(pkgName, description)
if err != nil {
log.Fatal("Aborted")
}
if isConfirmed {
internal.InstallPackage(pkgName)
fmt.Println("Usage: import \"" + pkgName + "\"")
} else {
log.Fatal("Aborted")
}
case INSTALL_SEARCH:
maxResultLength := 4
for _, subCommand := range recivedArgument {
switch subCommand.Commad {
case SEARCH_CAPACITY:
input_int, err := strconv.Atoi(subCommand.Value)
if err != nil {
fmt.Println("Warning: mx command must be a number, system defaulted to 4")
} else {
if input_int <= 0 {
fmt.Println("Warning: mx command must be a number greater then 0, system defaulted to 4")
} else {
maxResultLength = input_int
}
}
}
}
pkgNames := requests.ParseHttpString(commandStruct.Value, maxResultLength)
indexOfPackage, err := internal.ConsoleOutputMultipleChoise(pkgNames)
if err != nil {
log.Fatal(err)
}
internal.InstallPackage(pkgNames[indexOfPackage].PkgName)
fmt.Println("Usage: import \"" + pkgNames[indexOfPackage].PkgName + "\"")
}
}
}