aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/builder.lua4
-rw-r--r--src/lib/init.lua1
-rw-r--r--src/lib/manager.lua40
-rw-r--r--src/lib/path.lua14
4 files changed, 57 insertions, 2 deletions
diff --git a/src/lib/builder.lua b/src/lib/builder.lua
index 7390257..34c3c8c 100644
--- a/src/lib/builder.lua
+++ b/src/lib/builder.lua
@@ -3,13 +3,13 @@ Builder = {}
function Builder:from_template(path)
local builder = {
template = loadfile(
- path,
+ tostring(path),
nil,
Env.Sandbox {
Template = Template
}
)(),
- source = Path:new(path),
+ source = path,
}
builder.source_directory = builder.source:parent()
diff --git a/src/lib/init.lua b/src/lib/init.lua
index 2db3367..d87921c 100644
--- a/src/lib/init.lua
+++ b/src/lib/init.lua
@@ -3,3 +3,4 @@ require('lib.env')
require('lib.template')
require('lib.builder')
require('lib.instance')
+require('lib.manager')
diff --git a/src/lib/manager.lua b/src/lib/manager.lua
new file mode 100644
index 0000000..4ad2051
--- /dev/null
+++ b/src/lib/manager.lua
@@ -0,0 +1,40 @@
+manager = {}
+
+manager.base_path = Path:new(os.getenv('HOME')) / '.local/share/blueprint'
+manager.install_path = manager.base_path / 'templates'
+
+manager.base_path:make_directory { create_parents = true }
+manager.install_path:make_directory { create_parents = true }
+
+function manager.list()
+ return manager.install_path:entries()
+end
+
+function manager.install(path, name)
+ if not (path / 'build.lua'):exists() then
+ error('build.lua does not exist.')
+ end
+
+ local target = (manager.install_path / (name or path:name()))
+
+ if target:exists() then
+ error('template already installed.')
+ end
+
+ path:copy_to(target)
+end
+
+function manager.remove(name)
+ if name == nil or not (manager.install_path / name):exists() then
+ error('template does not exist.')
+ end
+
+ (manager.install_path / name):remove { recursive = true, force = true }
+end
+
+function manager.get(name)
+ if (manager.install_path / name):exists() then
+ return manager.install_path / name / 'build.lua'
+ end
+ return nil
+end
diff --git a/src/lib/path.lua b/src/lib/path.lua
index f99585b..a0be1e5 100644
--- a/src/lib/path.lua
+++ b/src/lib/path.lua
@@ -112,6 +112,20 @@ function Path:make_directory(opts)
pipe:close()
end
+function Path:copy_to(target)
+ local pipe = io.popen('cp -r ' .. tostring(self) .. ' ' .. tostring(target))
+ pipe:close()
+end
+
+function Path:remove(opts)
+ local pipe = io.popen('rm ' ..
+ (opts.recursive and '-r ' or ' ') ..
+ (opts.force and '-f ' or ' ') ..
+ tostring(self)
+ )
+ pipe:close()
+end
+
return {
tests = {
function()