1
1
local plugin_validate = require (" crazywall.validate" )
2
+ local validate = require (" core.validate" )
2
3
local default_config = require (" core.defaults.config" )
3
4
local PluginState = require (" lua.crazywall.state" )
4
5
local Config = require (" core.config" )
@@ -15,6 +16,60 @@ cmd_crazywall_dry(plugin_state)
15
16
cmd_crazywall_quick (plugin_state )
16
17
cmd_crazywall_follow_ref (plugin_state )
17
18
19
+ vim .api .nvim_create_user_command (" CrazywallListConfigs" , function ()
20
+ for name , _ in pairs (plugin_state .configs ) do
21
+ print (
22
+ name
23
+ .. (
24
+ name == plugin_state .current_config_name and " {active}"
25
+ or " "
26
+ )
27
+ )
28
+ end
29
+ print ()
30
+ end , {})
31
+
32
+ vim .api .nvim_create_user_command (" CrazywallSetConfig" , function (opts )
33
+ local config_name = opts .fargs [1 ]
34
+ if not plugin_state .configs [config_name ] then
35
+ return vim .api .nvim_err_writeln (
36
+ " crazywall: Could not find config " .. config_name .. " ."
37
+ )
38
+ end
39
+ plugin_state .current_config_name = config_name
40
+ end , {
41
+ nargs = 1 ,
42
+ complete = function (_ , line )
43
+ local args = vim .split (line , " " )
44
+ local config_names = {}
45
+ if # args ~= 2 then
46
+ return
47
+ end
48
+ for name , _ in pairs (plugin_state ) do
49
+ table.insert (config_names , name )
50
+ end
51
+ return config_names
52
+ end ,
53
+ })
54
+
55
+ M .add_config = function (name , config_table )
56
+ local err = validate .types (
57
+ ' require"crazywall".add_config()' ,
58
+ { { name , " string" , " name" } }
59
+ )
60
+ if err then
61
+ error (err )
62
+ end
63
+ local config
64
+ config , err = Config :new (config_table )
65
+ if not config then
66
+ error (
67
+ " Error occurred when trying to add config " .. name .. " : \n " .. err
68
+ )
69
+ end
70
+ plugin_state .configs [name ] = config_table
71
+ end
72
+
18
73
M .setup = function (opts )
19
74
opts = opts or {}
20
75
local keys = { " configs" , " default_config_name" , " follow_ref" }
0 commit comments