-
Notifications
You must be signed in to change notification settings - Fork 83
/
nvm.lua
46 lines (37 loc) · 1.06 KB
/
nvm.lua
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
local path = require('path')
local w = require('tables').wrap
local parser = clink.arg.new_parser
local NVM_ROOT
local function get_nvm_root()
if NVM_ROOT then return NVM_ROOT end
local proc = io.popen("2>nul nvm root")
if not proc then
NVM_ROOT = ""
return NVM_ROOT
end
local lines = proc:read('*all')
NVM_ROOT = lines:match("Current Root:%s(.*)%s*\n$") or ""
proc:close()
return NVM_ROOT
end
local installed = function ()
return w(clink.find_dirs(get_nvm_root().."/*"))
:filter(path.is_real_dir)
:map(function (dir)
return dir:match("v(.*)")
end)
end
local archs = parser({"64", "32"})
local nvm_parser = parser({
"arch"..archs,
"install"..parser({"latest"}, archs),
"list"..parser({installed, "available"}),
"ls"..parser({installed, "available"}),
"on", "off",
"proxy"..parser({"none"}),
"uninstall"..parser({installed}),
"use"..parser({installed}, archs),
"root",
"version", "v"
}, "-h", "--help", "-v", "--version")
clink.arg.register_parser("nvm", nvm_parser)