-
Notifications
You must be signed in to change notification settings - Fork 2
/
scoop.lua
152 lines (135 loc) · 3.86 KB
/
scoop.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
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
148
149
150
151
152
local scoop_dir = os.getenv('SCOOP')
if not scoop_dir then
scoop_dir = os.getenv('USERPROFILE')..'/scoop'
end
local scoop_global = os.getenv('SCOOP_GLOBAL')
if not scoop_global then
scoop_global = os.getenv('ProgramData')..'/scoop'
end
local function trim_extensions (apps)
for k, v in pairs(apps) do
apps[k] = string.match(v, '(.+)%.')
end
return apps
end
local function find_dirs (path)
return clink.find_dirs(path)
end
local function find_files (path)
return clink.find_files(path)
end
local function get_cache ()
cache = find_files(scoop_dir..'/cache/*')
for i, name in pairs(cache) do
signPos = string.find(name, "#")
cache[i] = signPos and string.sub(name, 0, signPos - 1) or nil
end
return cache
end
function get_installed_buckets ()
return find_dirs(scoop_dir..'/buckets/*')
end
function get_known_buckets ()
json = io.open(scoop_dir..'/apps/scoop/current/buckets.json')
known = {}
i = 0
for line in json:lines() do
known[i] = string.match(line, '\"(.-)\"')
i = i + 1
end
return known
end
function get_installed_apps ()
installed = find_dirs(scoop_dir..'/apps/*')
i = #installed
if scoop_global then
for _, dir in pairs(find_dirs(scoop_global..'/apps/*')) do
installed[i] = dir
i = i + 1
end
end
return installed
end
function get_known_apps ()
apps = {}
i = 0
for _, dir in pairs(get_installed_buckets()) do
for u, app in pairs(trim_extensions(clink.find_files(scoop_dir..'/buckets/'..dir..'/*.json'))) do
apps[i] = app
i = i + 1
end
for u, app in pairs(trim_extensions(clink.find_files(scoop_dir..'/buckets/'..dir..'/bucket/*.json'))) do
apps[i] = app
i = i + 1
end
end
return apps
end
local parser = clink.arg.new_parser
local boolean_parser = parser({'true', 'false'})
local architecture_parser = parser({'32bit', '64bit'})
local config_parser = parser({
'7ZIPEXTRACT_USE_EXTERNAL' ..boolean_parser,
'MSIEXTRACT_USE_LESSMSI' ..boolean_parser,
'aria2-enabled' ..boolean_parser,
'aria2-retry-wait',
'aria2-split',
'aria2-max-connection-per-server',
'aria2-min-split-size',
'aria2-retry-wait',
'aria2-options',
'debug' ..boolean_parser,
'rootPath',
'globalPath',
'default-architecture' ..architecture_parser,
'cachePath',
'shim' ..parser({'71', 'kiennq', 'default'}),
'NO_JUNCTIONS' ..boolean_parser,
'show_update_log' ..boolean_parser,
'virustotal_api_key',
'proxy'
})
local scoop_parser = parser({
{'info', 'depends', 'home'} ..parser({get_known_apps}),
'alias' ..parser({'add', 'list' ..parser({'-v', '--verbose'}), 'rm'}),
'bucket' ..parser({'add' ..parser({get_known_buckets}), 'list', 'known', 'rm' ..parser({get_installed_buckets})}),
'cache' ..parser({'show', 'rm'} ..parser({get_cache})),
'checkup',
'cleanup' ..parser({get_installed_apps},
'-g', '--global'):loop(1),
'config' ..config_parser,
'create',
'export',
'list',
'install' ..parser({get_known_apps},
'-g', '--global',
'-i', '--independent',
'-k', '--no-cache',
'-s', '--skip',
'-a' ..architecture_parser, '--arch' ..architecture_parser
):loop(1),
'prefix' ..parser({get_installed_apps}),
{'reset', 'hold', 'unhold'} ..parser({get_installed_apps}):loop(1),
'search',
'status',
'uninstall' ..parser({get_installed_apps},
'-g', '--global',
'-p', '--purge'):loop(1),
'update' ..parser({get_installed_apps},
'-g', '--global',
'-f', '--force',
'-i', '--independent',
'-k', '--no-cache',
'-s', '--skip',
'-q', '--quite'):loop(1),
'virustotal' ..parser({get_known_apps},
'-a' ..architecture_parser, '--arch' ..architecture_parser,
'-s', '--scan',
'-n', '--no-depends'):loop(1),
'which'
})
local help_parser = parser({
'help' ..parser(scoop_parser:flatten_argument(1))
})
clink.arg.register_parser('scoop', scoop_parser)
clink.arg.register_parser('scoop', help_parser)