This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
147 lines (134 loc) · 3.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"path"
"github.com/alexcoder04/arrowprint"
"github.com/alexcoder04/gilc"
"github.com/alexcoder04/lpm/commands"
"github.com/alexcoder04/lpm/initial"
"github.com/alexcoder04/lpm/repository"
"github.com/alexcoder04/lpm/settings"
"github.com/alexcoder04/lpm/utils"
)
func initSettings(data gilc.IData) error {
settings.Folders["config"] = path.Join(data.SavePath, "var", "lpm")
settings.Folders["temp"] = path.Join(data.DownloadPath, "apkg")
settings.Folders["root"] = data.SavePath
err := settings.UpdateConfig()
if err != nil {
return err
}
return nil
}
func pmain(data gilc.IData) {
arrowprint.Suc0("running PluginMain for lpm")
err := initSettings(data)
if err != nil {
arrowprint.Err0("cannot load config: %s", err.Error())
return
}
// create folders
err = initial.CreateVarFolders()
if err != nil {
arrowprint.Err0("cannot create var folders: %s", err.Error())
return
}
repository.Reload()
if !utils.StringArrayContains(repository.GetListInstalled(), "lpm") {
arrowprint.Warn0("lpm is not installed properly, installing...")
err := repository.InstallPackage("lpm")
if err != nil {
arrowprint.Err0("cannot install lpm: %s", err.Error())
return
}
}
}
func pcommand(data gilc.IData, args []string) {
if len(args) < 1 {
arrowprint.Err0("you need pass a subcommand, try 'lpm help'")
return
}
err := initSettings(data)
if err != nil {
arrowprint.Err0("cannot load config: %s", err.Error())
return
}
switch args[0] {
case "list-available", "a":
commands.ListAvailable()
return
case "build", "b":
if !settings.CurrentConfig.DebugMode {
arrowprint.Err0("this command is only available in debug mode")
return
}
if len(args) < 2 {
arrowprint.Err0("you need to pass an argument")
return
}
res, err := repository.BuildFolder(args[1])
if err != nil {
arrowprint.Err0("error building %s: %s", args[1], err.Error())
return
}
arrowprint.Info0("package was saved to %s", res)
return
case "config", "conf", "cfg", "c":
commands.Config(args)
return
case "get-local", "d":
if !settings.CurrentConfig.DebugMode {
arrowprint.Err0("this command is only available in debug mode")
return
}
if len(args) < 2 {
arrowprint.Err0("you need to pass an argument")
return
}
err := commands.GetLocal(args[1])
if err != nil {
arrowprint.Err0("error installing %s: %s", args[1], err.Error())
}
return
case "search", "f":
commands.Search(args)
return
case "help", "h":
commands.Help()
return
case "get", "install", "i":
if len(args) < 2 {
arrowprint.Err0("you need to pass the package name")
return
}
err := repository.InstallPackage(args[1])
if err != nil {
arrowprint.Err0("error installing %s: %s", args[1], err.Error())
}
return
case "list-installed", "l":
commands.ListInstalled()
return
case "remove", "uninstall", "r":
if len(args) < 2 {
arrowprint.Err0("you need to pass the package name")
return
}
repository.RemovePackage(args[1])
return
case "reload", "sync", "s":
repository.Reload()
return
case "update", "upgrade", "u":
commands.Update()
return
default:
arrowprint.Err0("unknown subcomand: '%s', try 'lpm help'", args[0])
return
}
}
func pshutdown(data gilc.IData) {
}
func main() {
gilc.Setup("leoconsole package manager", pmain, pcommand, pshutdown)
gilc.Run()
}