-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.odin
48 lines (38 loc) · 1.03 KB
/
get.odin
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
package nopm
import "core:fmt"
import "core:log"
import os "core:os/os2"
import sp "core:path/slashpath"
import st "core:strings"
CmdGet :: struct {
get: string `args:"pos=0,hidden"`,
url: string `args:"pos=1,required"`,
global: bool `args:"name=g"`,
odin_path: string `args:"name=op"`,
}
LIBS_DIR :: "libs"
DEFAUL_CONFIG_PATH :: ".config/nopm/config.json"
parse_lib_name :: proc(url: string) -> (name: string) {
url_split := st.split(url, "/")
git_name := url_split[len(url_split) - 1]
name = st.trim_suffix(git_name, ".git")
return
}
command_get :: proc(model: ^CmdGet, opt: ^Options) {
cfg := load_config(DEFAUL_CONFIG_PATH)
ld: string
if model.global {
if model.odin_path == "" {
ld = sp.join({cfg.odin_path, "shared"})
} else {
ld = sp.join({model.odin_path, "shared"})
}
} else {
create_libs_path(opt.cwd)
ld = create_libs_path(opt.cwd)
}
lib_name := parse_lib_name(model.url)
result_wd := sp.join({ld, lib_name})
os.chdir(ld)
cmd_process_replace("git", "clone", model.url, result_wd)
}