11local MODSTR = ' project.commands'
22local ERROR = vim .log .levels .ERROR
33local INFO = vim .log .levels .INFO
4+ local validate = vim .validate
45
56local vim_has = require (' project.utils.util' ).vim_has
67
@@ -23,35 +24,35 @@ local vim_has = require('project.utils.util').vim_has
2324--- @field create_user_commands fun ()
2425
2526--- @type Project.Commands | table<string , Project.CMD>
26- local Commands = {}
27+ local M = {}
2728
2829--- @param spec Project.Commands.Spec
29- function Commands .new (spec )
30+ function M .new (spec )
3031 if vim_has (' nvim-0.11' ) then
31- vim . validate (' spec' , spec , ' table' , false , ' Project.Commands.Spec' )
32+ validate (' spec' , spec , ' table' , false , ' Project.Commands.Spec' )
3233 else
33- vim . validate ({ spec = { spec , ' table' } })
34+ validate ({ spec = { spec , ' table' } })
3435 end
3536
3637 if vim .tbl_isempty (spec ) then
3738 error ((' (%s.new): Empty command spec!' ):format (MODSTR ), ERROR )
3839 end
3940
4041 if vim_has (' nvim-0.11' ) then
41- vim . validate (' name' , spec .name , ' string' , false )
42- vim . validate (' callback' , spec .callback , ' function' , false )
43- vim . validate (' desc' , spec .desc , ' string' , false )
44- vim . validate (' bang' , spec .bang , ' boolean' , true , ' boolean?' )
45- vim . validate (' nargs' , spec .nargs , { ' string' , ' number' }, true , ' (string|integer)?' )
46- vim . validate (
42+ validate (' name' , spec .name , ' string' , false )
43+ validate (' callback' , spec .callback , ' function' , false )
44+ validate (' desc' , spec .desc , ' string' , false )
45+ validate (' bang' , spec .bang , ' boolean' , true , ' boolean?' )
46+ validate (' nargs' , spec .nargs , { ' string' , ' number' }, true , ' (string|integer)?' )
47+ validate (
4748 ' complete' ,
4849 spec .complete ,
4950 { ' function' , ' string' },
5051 true ,
5152 ' (string|CompletorFun)?'
5253 )
5354 else
54- vim . validate ({
55+ validate ({
5556 name = { spec .name , ' string' },
5657 callback = { spec .callback , ' function' },
5758 desc = { spec .desc , ' string' },
@@ -60,6 +61,12 @@ function Commands.new(spec)
6061 complete = { spec .complete , { ' string' , ' function' , ' nil' } },
6162 })
6263 end
64+ if spec .name == ' ' then
65+ error ((' (%.new): No user command name provided!' ):format (MODSTR ))
66+ end
67+ if spec .desc == ' ' then
68+ error ((' (%.new): No user command description provided!' ):format (MODSTR ))
69+ end
6370
6471 --- @type { name : string , desc : string , bang : boolean , complete ?: string | CompletorFun , nargs ?: string | integer }
6572 local T = {
@@ -76,7 +83,7 @@ function Commands.new(spec)
7683 T .complete = spec .complete
7784 end
7885
79- Commands [spec .name ] = setmetatable ({}, {
86+ M [spec .name ] = setmetatable ({}, {
8087 --- @param k string
8188 __index = function (_ , k )
8289 return T [k ]
@@ -98,7 +105,7 @@ function Commands.new(spec)
98105 })
99106end
100107
101- Commands .new ({
108+ M .new ({
102109 name = ' ProjectAdd' ,
103110 callback = function (ctx )
104111 local quiet = ctx .bang ~= nil and ctx .bang or false
@@ -108,7 +115,7 @@ Commands.new({
108115 bang = true ,
109116})
110117
111- Commands .new ({
118+ M .new ({
112119 name = ' ProjectDelete' ,
113120 callback = function (ctx )
114121 local force = ctx .bang ~= nil and ctx .bang or false
@@ -153,7 +160,7 @@ Commands.new({
153160 end ,
154161})
155162
156- Commands .new ({
163+ M .new ({
157164 name = ' ProjectConfig' ,
158165 callback = function ()
159166 local cfg = require (' project' ).get_config ()
@@ -162,15 +169,15 @@ Commands.new({
162169 desc = ' Prints out the current configuratiion for `project.nvim`' ,
163170})
164171
165- Commands .new ({
172+ M .new ({
166173 name = ' ProjectFzf' ,
167174 callback = function ()
168175 require (' project.extensions.fzf-lua' ).run_fzf_lua ()
169176 end ,
170177 desc = ' Run project.nvim through Fzf-Lua (assuming you have it installed)' ,
171178})
172179
173- Commands .new ({
180+ M .new ({
174181 name = ' ProjectNew' ,
175182 callback = function ()
176183 local Api = require (' project.api' )
@@ -183,7 +190,7 @@ Commands.new({
183190 desc = ' Run the experimental UI for project.nvim' ,
184191})
185192
186- Commands .new ({
193+ M .new ({
187194 name = ' ProjectRoot' ,
188195 callback = function (ctx )
189196 local verbose = ctx .bang ~= nil and ctx .bang or false
@@ -193,7 +200,7 @@ Commands.new({
193200 bang = true ,
194201})
195202
196- Commands .new ({
203+ M .new ({
197204 name = ' ProjectSession' ,
198205 callback = function ()
199206 local session = require (' project.utils.history' ).session_projects
@@ -214,7 +221,7 @@ Commands.new({
214221 desc = ' Prints out the current `project.nvim` projects session' ,
215222})
216223
217- Commands .new ({
224+ M .new ({
218225 name = ' ProjectTelescope' ,
219226 callback = function ()
220227 if vim .g .project_telescope_loaded == 1 then
@@ -224,71 +231,71 @@ Commands.new({
224231 desc = ' Telescope shortcut for project.nvim picker' ,
225232})
226233
227- function Commands .create_user_commands ()
234+ function M .create_user_commands ()
228235 --- `:ProjectAdd`
229- vim .api .nvim_create_user_command (' ProjectAdd' , function (ctx )
230- Commands .ProjectAdd (ctx )
236+ vim .api .nvim_create_user_command (M . ProjectAdd . name , function (ctx )
237+ M .ProjectAdd (ctx )
231238 end , {
232- bang = Commands .ProjectAdd .bang ,
233- desc = Commands .ProjectAdd .desc ,
239+ bang = M .ProjectAdd .bang ,
240+ desc = M .ProjectAdd .desc ,
234241 })
235242
236243 --- `:ProjectConfig`
237- vim .api .nvim_create_user_command (' ProjectConfig' , function ()
238- Commands .ProjectConfig ()
244+ vim .api .nvim_create_user_command (M . ProjectConfig . name , function ()
245+ M .ProjectConfig ()
239246 end , {
240- desc = Commands .ProjectConfig .desc ,
247+ desc = M .ProjectConfig .desc ,
241248 })
242249
243250 --- `:ProjectDelete`
244- vim .api .nvim_create_user_command (' ProjectDelete' , function (ctx )
245- Commands .ProjectDelete (ctx )
251+ vim .api .nvim_create_user_command (M . ProjectDelete . name , function (ctx )
252+ M .ProjectDelete (ctx )
246253 end , {
247- desc = Commands .ProjectDelete .desc ,
248- bang = Commands .ProjectDelete .bang ,
249- nargs = Commands .ProjectDelete .nargs ,
250- complete = Commands .ProjectDelete .complete ,
254+ desc = M .ProjectDelete .desc ,
255+ bang = M .ProjectDelete .bang ,
256+ nargs = M .ProjectDelete .nargs ,
257+ complete = M .ProjectDelete .complete ,
251258 })
252259
253260 --- `:ProjectNew`
254- vim .api .nvim_create_user_command (' ProjectNew' , function ()
255- Commands .ProjectNew ()
261+ vim .api .nvim_create_user_command (M . ProjectNew . name , function ()
262+ M .ProjectNew ()
256263 end , {
257- desc = Commands .ProjectNew .desc ,
264+ desc = M .ProjectNew .desc ,
258265 })
259266
260267 --- `:ProjectRoot`
261- vim .api .nvim_create_user_command (' ProjectRoot' , function (ctx )
262- Commands .ProjectRoot (ctx )
268+ vim .api .nvim_create_user_command (M . ProjectRoot . name , function (ctx )
269+ M .ProjectRoot (ctx )
263270 end , {
264- bang = Commands .ProjectRoot .bang ,
265- desc = Commands .ProjectRoot .desc ,
271+ bang = M .ProjectRoot .bang ,
272+ desc = M .ProjectRoot .desc ,
266273 })
267274
268275 --- `:ProjectSession`
269- vim .api .nvim_create_user_command (' ProjectSession' , function ()
270- Commands .ProjectSession ()
276+ vim .api .nvim_create_user_command (M . ProjectSession . name , function ()
277+ M .ProjectSession ()
271278 end , {
272- desc = Commands .ProjectSession .desc ,
279+ desc = M .ProjectSession .desc ,
273280 })
274281
275282 if require (' project.config' ).options .fzf_lua .enabled then
276283 --- `:ProjectFzf`
277- vim .api .nvim_create_user_command (' ProjectFzf' , function ()
278- Commands .ProjectFzf ()
284+ vim .api .nvim_create_user_command (M . ProjectFzf . name , function ()
285+ M .ProjectFzf ()
279286 end , {
280- desc = Commands .ProjectFzf .desc ,
287+ desc = M .ProjectFzf .desc ,
281288 })
282289 end
283290
284291 --- `:ProjectTelescope`
285- vim .api .nvim_create_user_command (' ProjectTelescope' , function ()
286- Commands .ProjectTelescope ()
292+ vim .api .nvim_create_user_command (M . ProjectTelescope . name , function ()
293+ M .ProjectTelescope ()
287294 end , {
288- desc = Commands .ProjectTelescope .desc ,
295+ desc = M .ProjectTelescope .desc ,
289296 })
290297end
291298
292- return Commands
299+ return M
293300
294301-- vim:ts=4:sts=4:sw=4:et:ai:si:sta:
0 commit comments