-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpetals.lua
108 lines (92 loc) · 2.47 KB
/
petals.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
-- i have the tendancy to make everything i code a mess
-- petals is no exception
-- excuse: its in alpha :^)
local commander = require 'commander'
local fs = require 'fs'
local utils = require 'petals.utils'
local petals = {}
local plugtable = {
notinstalled = {},
notstarted = {},
started = {}
}
petals.ver = '0.0.3'
-- Init adds the `petals` command for plugin management in interactive mode
petals.init = function()
commander.register('petals', function(args)
if #args < 1 then
print(help)
return
end
local cmd = args[1]
if cmd == 'help' then
print(help)
elseif cmd == 'install' then
for p, props in pairs(plugtable.notinstalled) do
local ok, code, msg = petals.install(p, props)
if ok then
print('✔️ Successfully installed ' .. p .. '!')
else
print('✖️ Unsuccessfully installed ' .. p .. '.\n'
.. 'Reason: ' .. msg)
end
end
elseif cmd == 'version' then
print(petals.ver)
else
print 'unknown command'
print 'run "petals help" for commands and usage'
end
end)
end
-- Loads plugins
petals.load = function(plug)
local plugurl = plug
local manifest = {}
if type(plug) == 'table' then
plugurl = plug[1]
manifest = plug
end
local exists = utils.exists(plugurl, manifest.module)
if not exists then
plugtable.notinstalled[plugurl] = manifest
else
if manifest.module then
utils.addPackage(plugurl)
else
manifest = utils.getmanifest(plugurl)
plugtable.notstarted[plugurl] = manifest
end
end
end
-- Installs a single plugin
petals.install = function(plugurl, opts)
local path = ''
if opts.module then
path = utils.expand '~/.local/share/hilbish/petals/libs/' .. plugurl
else
path = utils.expand '~/.local/share/hilbish/petals/start/' .. plugurl
end
local ok = utils.clone(plugurl, path)
if not ok then return false, 1, 'repository not found' end
plugtable.notinstalled[plugurl] = nil
plugtable.notstarted[plugurl] = utils.getmanifest(path)
return true, 0, success
end
-- Actually starts up our plugins
petals.start = function()
for p, props in pairs(plugtable.notstarted) do
dofile(utils.expand '~/.local/share/hilbish/petals/start/' .. p .. '/src/plugin.lua')
plugtable.notstarted[p] = nil
plugtable.started[props.name] = props
end
end
local help = string.format [[
Usage: petals <command>
Hilbish plugin manager.
Available commands:
help - This help page
install - Installs loaded plugins that aren't installed
version - Prints the version of Petals
]]
return petals