diff options
Diffstat (limited to 'lua/tasks/project_config.lua')
-rw-r--r-- | lua/tasks/project_config.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lua/tasks/project_config.lua b/lua/tasks/project_config.lua new file mode 100644 index 0000000..2d366c6 --- /dev/null +++ b/lua/tasks/project_config.lua | |||
@@ -0,0 +1,29 @@ | |||
1 | local config = require('tasks.config') | ||
2 | local Path = require('plenary.path') | ||
3 | |||
4 | --- Contains all fields from configuration. | ||
5 | ---@class ProjectConfig | ||
6 | local ProjectConfig = {} | ||
7 | ProjectConfig.__index = ProjectConfig | ||
8 | |||
9 | --- Reads project configuration JSON into a table. | ||
10 | ---@return ProjectConfig | ||
11 | function ProjectConfig.new() | ||
12 | local project_config = {} | ||
13 | local params_file = Path:new(config.params_file) | ||
14 | if params_file:is_file() then | ||
15 | project_config = vim.json.decode(params_file:read()) | ||
16 | else | ||
17 | project_config = {} | ||
18 | end | ||
19 | project_config = vim.tbl_extend('keep', project_config, config.default_params) | ||
20 | return setmetatable(project_config, ProjectConfig) | ||
21 | end | ||
22 | |||
23 | --- Writes all values as JSON to disk. | ||
24 | function ProjectConfig:write() | ||
25 | local params_file = Path:new(config.params_file) | ||
26 | params_file:write(vim.json.encode(self), 'w') | ||
27 | end | ||
28 | |||
29 | return ProjectConfig | ||