-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
66 lines (47 loc) · 1.51 KB
/
init.lua
File metadata and controls
66 lines (47 loc) · 1.51 KB
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
local config = require("cppm.config")
local util = require("cppm.util")
local scan = require('plenary.scandir')
local cppm = {}
function cppm.setup(opts)
if (cppm._config_exists()) then
return util.error("Attempted to setup more than once, this is an error.")
end
local cfg = config.apply_defaults(opts)
-- Allow the rest of the module to access the config
cppm.config = cfg
end
function cppm.enable()
if (not cppm._config_exists()) then
return util.error("You must call setup() before using CPPM")
end
cppm.config.enabled = true
local opts = {
hidden = true,
depth = 2,
search_pattern = cppm.config.cfg_files,
respect_gitignore = true
}
local cwd_files = scan.scan_dir(".", opts)
if (util.tbl_empty(cwd_files)) then
return util.warn('No CPPM config files could be found.')
end
local chosen_path = table.remove(cwd_files, 1)
if (not util.tbl_empty(cwd_files)) then
return util.warn(string.format('Found multiple entries for CPPM config files, using %s', chosen_path))
end
local toml = config.parse_config(chosen_path)
for index, value in ipairs(toml) do
vim.notify(string.format("I %s, V %s", index, value))
end
end
function cppm.disable()
if (not cppm._config_exists()) then
return util.error("You must call setup() before using CPPM")
end
cppm.config.enabled = false
end
-- Private API
function cppm._config_exists()
return cppm.config ~= nil
end
return cppm