Skip to content

Commit 4d33be3

Browse files
committed
Make it easier to build an Artisan command
`laravel#app().makeprg()` now accepts one or more arguments, which are concatenated to the result.
1 parent 88a2027 commit 4d33be3

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

autoload/laravel.vim

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,30 @@ endfunction
307307

308308
call s:add_methods('app', ['facades', 'routes', 'templates'])
309309

310-
function! s:app_makeprg() abort dict
311-
return 'php artisan'
310+
""
311+
" Get artisan command line, optionally including [args].
312+
"
313+
" echo laravel#app().makeprg()
314+
" => 'php artisan'
315+
"
316+
" echo laravel#app().makeprg('route:list')
317+
" => 'php artisan route:list'
318+
"
319+
" Arguments may be passed as individual function parameters or as a list.
320+
"
321+
" echo laravel#app().makeprg(['route:list', '-vvv'])
322+
" echo laravel#app().makeprg('route:list', '-vvv')
323+
" => 'php artisan route:list -vvv'
324+
function! s:app_makeprg(...) abort dict
325+
if a:0 == 1 && type(a:1) == type([])
326+
let args = a:1
327+
elseif a:0 > 1
328+
let args = copy(a:000)
329+
else
330+
let args = []
331+
endif
332+
333+
return join(['php', 'artisan'] + args)
312334
endfunction
313335

314336
call s:add_methods('app', ['makeprg'])

autoload/laravel/artisan.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ endfunction
4040
function! s:artisan_exec(args) abort
4141
try
4242
let cwd = s:cd(laravel#app().path())
43-
let result = systemlist(join([laravel#app().makeprg()] + a:args))
43+
let result = systemlist(laravel#app().makeprg(a:args))
4444
finally
4545
call s:cd(cwd)
4646
endtry
@@ -76,10 +76,10 @@ function! laravel#artisan#exec(...) abort
7676
" if exists(':terminal')
7777
" tabedit %
7878
" execute 'lcd' fnameescape(laravel#app().path())
79-
" execute 'terminal' laravel#app().makeprg() join(args)
79+
" execute 'terminal' laravel#app().makeprg(args)
8080
" else
8181
let cwd = s:cd(laravel#app().path())
82-
execute '!' . laravel#app().makeprg() join(args)
82+
execute '!' . laravel#app().makeprg(args)
8383
call s:cd(cwd)
8484
" endif
8585

0 commit comments

Comments
 (0)